Write a python program that outputs all the even numbers

Assignment Help Python Programming
Reference no: EM133059353

Learning Activity 1 - Programming Exercises

Exercise 1. Print numbers in reverse order
Write a Python program that outputs all integers from a given number down to 1, separated by comma. The program will first ask the user to input a positive integer, it will then output all the numbers from that number (inclusive) to 1. For example, if the user types in 10, your program should output 10,9,8,7,6,5,4,3,2,1. If the user types in 5, your program should output 5,4,3,2,1.

Sample input/output:
>>> Enter a positive integer:
>>> 20
>>> 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1

This learning activity asks you to write a program.

Please upload your code as a Python code file (.py file) to Module 3.1 Programming Exercises- Easy Discussion Forum and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.

Please check other students' code and comment on why you agree, disagree or can provide help with another students' post. Please reply to at least two other students' posts.

Exercise 2. Even numbers
Write a Python program that outputs all the even numbers from 2 to a number (inclusive) provided by the user, separated by comma. The program will first ask the user to input an integer that is greater than 2, it will then output all the even numbers from 2 to that number. For example, if the user types in 10, your program should output 2,4,6,8,10. If the user types in 13, your program should output 2,4,6,8,10,12.

Sample input/output:
>>> Enter an integer greater than 2:
>>> 11
>>> 2,4,6,8,10

This learning activity asks you to write a program.

Please upload your code as a Python code file (.py file) to Module 3.1 Programming Exercises- Easy Discussion Forum and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.

Please check other students' code and comment on why you agree, disagree or can provide help with another students' post. Please reply to at least two other students' posts.

Exercise 3. Find a particular number in a random list

NOTE: this learning activity requires Python 3.6 or higher. In Module 1.1, you were asked to install any Python version higher than 3.6. If you use a version lower than Python 3.6, some of the code will not work.

In this learning activity, we will implement an algorithm that we discussed in Module 2.2. We asked you to draw a flowchart and write some pseudocode for a linear search algorithm, that is, to find a particular value, key, in an arbitrary list.

Your program will first start with the following two lines of code:

import random
l = random.choices(range(100), 50)

These two lines of code create a list, l, which contains 50 integers randomly samples from range [0, 100). This range includes the left-hand number 0, but does not include the right-hand side number 100.

You now need to ask the user the type in a number, then perform a linear search over the random list l. If you can find the number from the list, then print "Yes, I found it!", otherwise, print "No, it does not exist in the list".

Sample input/output:
>>> Enter a number:
>>> 100
>>> No, it does not exist in the list

This learning activity asks you to write a program.

Please upload your code as a Python code file (.py file) to Module 3.1 Programming Exercises- Easy Discussion Forum and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.

Please check other students' code and comment on why you agree, disagree or can provide help with another students' post. Please reply to at least two other students' posts.

Exercise 4. Find a particular number in a random list
NOTE: this learning activity requires Python 3.6 or higher. In Module 1.1, you were asked to install any Python version higher than 3.6. If you use a version lower than Python 3.6, some of the code will not work.

In this learning activity, we will implement an algorithm that we discussed in Module 2.2. We asked you to draw a flowchart and write some pseudocode for a linear search algorithm, that is, to find a particular value, key, in an arbitrary list.

Your program will first start with the following two lines of code:

import random
l = random.choices(range(100), k = 50)

These two lines of code create a list, l, which contains 50 integers randomly samples from range [0, 100). This range includes the left-hand number 0, but does not include the right-hand side number 100. For example, this can be a list generated by these two lines of code:

[16, 56, 85, 8, 98, 50, 71, 81, 56, 12, 75, 24, 10, 60, 38, 25, 7, 98, 89, 3, 89, 27, 69, 46, 14, 15, 23, 15, 22, 47, 8,
81, 24, 94, 97, 40, 69, 2, 29, 59, 44, 32, 69, 37, 53, 91, 46, 14, 72, 94]

Every time you run these two lines of code you are likely to get a different list of numbers.

You now need to ask the user the type in a number, then perform a linear search over the random list l. If you
can find the number from the list, then print "Yes, I found it!", otherwise, print "No, it does not exist in the list".

Sample input/output:
>>> Enter a number:
>>> 100
>>> No, it does not exist in the list

Reference no: EM133059353

Questions Cloud

What is the value of HBB Company : HBB Company for the last ten years, has earned and had cash flows of about Php 500,000 every year. What is the value of HBB Company
Write a python program that computes the summation : Find a particular number in a random list - Implement a linear search algorithm, but this time, if you find the number in the list, return the index
What are the possible consequences : Question - Read the Ethical Issue case about Becky Knauer and her position with Mueller Imports. What are the possible consequences
Programming Exercise - Fibonacci series : Programming Exercise - Fibonacci series - write a Python program that allows the user to type in an integer n. Your program will then output the first n terms
Write a python program that outputs all the even numbers : Write a Python program that outputs all the even numbers from 2 to a number (inclusive) provided by the user, separated by comma
Draw a flowchart and write up some pseudocode : Draw a flowchart and write up some pseudocode for searching for a particular element in an arbitrary list.
Write a simple income tax calculator in Python : Write a simple income tax calculator in Python. Australia adopts a progressive income tax regime
Programming exercise - facilitators favourite number : Write a Python program that allows the user to type in a three-digit number. If the number is your learning facilitators favourite number, then output Yes
Programming exercise - odd or even number : Programming exercise - Write a Python program that determines whether a user's input number is an odd or even number.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd