Question

PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...

PROJECT 6    Functions

You are to write a PYTHON program which:

*Defines the following 4  functions:

whoamI()

This function prints out your name and lists any programming course you have taken prior to this course.

isEven(number)

This function accepts one parameter, a number, and prints out a message indicating if the number is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two.

printEven(number)

This function accepts one parameter, a number, and prints out all even values from 2 thru this number.

countDown(number)

This function accepts one parameter, a number, and prints out ALL values from this number down thru 1.

It would be a good idea to write a simple main to test your functions individually and make sure they work before you continue on.

* follows the function definition with main process statements which:

1.) calls the 'whoamI' function to that the program begins by outputting uses information

2.) prompt the user for a positive int and store it

   If the user does not enter a valid number, reprompt. Continue this until a valid value

   has been entered.

3.) present the user with 3 choices:  

              -find out if the number is even or odd

              -see printout of all even values up to the number

              -see printout of all values from number downto 1

4.) Carry out the user’s choice. Be sure to call one of the functions that you have defined to do this.

If you wish you may put the main statements in a loop which repeats until the user chooses to exit. This will make testing easier.

Your program should be well-tested and results readable. Function definitions should be commented indicating what each function does, and the main process should also be clearly commented.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#Displays user information
def whoamI() :
   print("Name : Dytalov")
   courses = ["HTML5 Introduction"];
   print("Courses completed : ")
   for course in courses :
       print("#",course)

# Prints if a number is even or odd
def isEven(number) :
   if number%2 == 0 :
       print("Even")
   else :
       print("Odd")

# Prints all even numbers from 2 through argument
def printEven(number) :
   for i in range(2,number) :
       if i%2 == 0 :
           print(i)

# Prints values of all numbers from argument downthrough 1
def countDown(number) :
   while number >= 1 :
       print (number)
       number = number - 1

# Input a positive number from user
def getNumber() :
   n = int(input("Enter a postive integer : "))
   while n <= 0 :
       n = int(input("Enter a postive integer : "))
   return n

whoamI()

x = "y"
while x == "y" or x == "Y" :
   n = getNumber()
   print("Enter your choice : ")
   print("1 - find out if the number is even or odd")
   print("2 - see printout of all even values up to the number")
   print("3 - see printout of all values from number downto 1")
  
   while True :
       print("Enter 1, 2 or 3")
       choice = int(input())
       if choice == 1:
           isEven(n)
           break
       if choice == 2:
           printEven(n)
           break
       if choice == 3:
           countDown(n)
           break

   x = input("Continue ? y/n")

Add a comment
Know the answer?
Add Answer to:
PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • please can you help me to solve it in Mips Assembly that works on Mars 4.5:...

    please can you help me to solve it in Mips Assembly that works on Mars 4.5: The function isEven, tests whether a number num is even or not. Write the main function of a program that reads a nuber num, calls the function isEven and then prints a message to indicate whether num is even or not. And then, ask the user if she wants to continue or not (Y/N). please answer it

  • **IN C*** * In this lab, you will write a program with three recursive functions you...

    **IN C*** * In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...

  • in Python: Write a program that allows the user to enter a number between 1-5 and...

    in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts: An octopus is a highly intelligent invertebrate and a master of disguise. Elephants...

  • Write a C program to do the following 1) request user to enter 10 integer into...

    Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...

  • DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a...

    DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a function called inch2cm that takes one number in inches as a parameter, converts it to the centimeters and prints the result. The program output is shown below. Input: 14 Output: 14 inches = 35.56 centimeter Write a program and create the following functions: shapes(): takes the shape name and a number as parameters, and calls the proper function to calculate the area. areaCircle(): take...

  • Write a driver C++ program that will test the following functions in the same order they...

    Write a driver C++ program that will test the following functions in the same order they are written next. You can test your program by reading the following values: n1= 10 and n2= 20 from the user: The main program sends the values of the variables n1 and n2 to the function. The function calculates the average and sends it back to main program through the parameter list as call by reference parameter and will not use the return statement.

  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT