Question

In: Computer Science

Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out...

Write a program in PYTHON which:

*Defines the following 5 functions:

whoamI()

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

isEven(number)

This function accepts one parameter, a number, and PRINTS OUT a message telling if the numberer 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.

sumUp(number)

This function accepts one parameter, a number, and RETURNS the sum of ALL values from 1 up to this number

howmanyDigits(number)

This function accepts one parameter, a number, and RETURNS the number of digits contained in the value. (for example, if the value was 475, the function would return a 3. Hint: the simplest way to do this is to convert the number to a string .. then the length is accessible

* 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 4 choices:  

              -find out if the number is even or odd

              - printout all even values up to the number

              -output the sum of all values from one to the number

- output the number of digits in the number

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 that repeats until the user chooses to exit.  

Solutions

Expert Solution

def whoami(): #define whoami()
print("I am Robert Chalse")
print("I have covered basic languages like C,C++,JAVA")
#define isEven()
def isEven(n):
if n % 2 == 0: #condition for even numbers
print(n," is an even number")
else:
print(n,"is an odd number")
#define printEven()
def printEven(n):
for i in range(2,n+1): #loop will runs from 2 to n
if(i%2==0): #check for even
print(i,end=" ") #print the even number
#define sumUpNumber()
def sumUpNumber(n):
total=0
for i in range(1,n+1): #loop runs from 1 to n
total = total + i #find the sum of all numbers
return total #return the sum
#define howmanyDigits()
def howmanyDigits(n) :
count=0
while (n!=0): #loop will execute till number not equal to zero
count=count+1 #count the nu,mber of digits
n = (int)(n/10)#reduce the number by one digit
return count #return count
  
  
whoami() #call whoami()
#infinite loop is used to input a positive number
#this loop will continue if user will eneter 0 or -ve numbers
while(1):
n = (int)(input("Enter a positive number"));
if (n>0): #check for positive number
break #terminate the loop
#infinite loop is used to operate the menu operations
while(1):
#display the menus
print("1. Check Even or ODD")
print("2. Print all even numbers from 1 to n")
print("3. Print the sum of all numers from 1 to n")
print("4. Count the number of digits in the number")
print("Which operation do you want : ")
opt=(int)(input("Enter your choice")) #read the choice of user
if(opt==1):
isEven(n)
else:
if(opt==2):
printEven(n)
else:
if(opt==3):
print("")
print("Sum of Numbers from 1 to ",n," is ",sumUpNumber(n))
else:
if(opt==4):
print("The total number of digits in ",n," is ",howmanyDigits(n))
else:
print("Invalid Choice");
#ask user to ocntinue more or not
ch = input("Do you want to operate more[Y/N]")
if(ch=='N' or ch=='n'):
break; #the loop will terminate if user will eneter n or N
  

OUTPUT

PROGRAM IN JPEG FORMAT


Related Solutions

Program in Python Problem Statement Write a program with the following functions:  wordCount. This function...
Program in Python Problem Statement Write a program with the following functions:  wordCount. This function should accept a string as a parameter and return the number of words contained in the string.  mostFrequentWord. This function accepts a string as a parameter and returns the word that occurs the most frequently in the string.  replaceWord. This function accepts three strings as parameters, let’s call them string1, string2, and string3. It searches string1 for all occurrences of string2. When...
In Python write a program that calculates and prints out bills of the city water company....
In Python write a program that calculates and prints out bills of the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of r means residential use, a code of c means commercial use, and a code of i means industrial use. Any other code should be treated as an error. The water rates are computed as follows:Three types of customers and their billing rates: Code...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which are less than 100. Your loop initially starts from 0. 2. Consider B to be a list of alphabetically ordered strings. Using while loops, write a program that only prints words which start with letter A. B = [Alex, Airplane, Alpha, Australia, Ben, Book, Bank, Circuit, Count, Dark] 3. Using while loop, create a program that only prints first 18 multiples of 7.Hint: Your...
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
In python write a program which prints the longest substring of numbers which occur in ascending...
In python write a program which prints the longest substring of numbers which occur in ascending order s=342153476757561235
Write a program which prompts the user for a positive integer, and then prints out the...
Write a program which prompts the user for a positive integer, and then prints out the prime factorization of their response. Do not import anything other than the Scanner. One way you might go about this using nested loops: Start a "factor" variable at 2 In a loop: repeatedly print the current factor, and divide the user input by it, until the user input is no longer divisible by the factor increment the factor This plan is by no stretch...
Use Python to solve: show all work 1) Write a program that prints out a deck...
Use Python to solve: show all work 1) Write a program that prints out a deck of cards, in the format specified below. (That is, the following should be the output of your code). 2 of hearts 2 of diamonds 2 of spades 2 of clubs 3 of hearts 3 of diamonds 3 of spades 3 of clubs 4 of hearts 4 of diamonds 4 of spades 4 of clubs Continue with 5,6,7.. ending with A of hearts A of...
Python: Write a program that plays Tic-tac-toe with a user. Each round, the game prints out...
Python: Write a program that plays Tic-tac-toe with a user. Each round, the game prints out the state of the board, asks the user where they would like to place their mark, and implements this decision. The program then places its own mark on a randomly chosen available position. Once one of the player won, the program declares the result and asks if the user would like to continue. The first player is selected at random.
Create a python program that prints the series from 5 to 500.
Create a python program that prints the series from 5 to 500.
1. Write a Python program that performs the following: 2. Defines an array of integers from...
1. Write a Python program that performs the following: 2. Defines an array of integers from 1 to 10. The numbers should be filled automatically without the need for user inputs 3. Find the sum of the numbers that are divisible by 3 (i.e., when a number is divided by 3, the remainder is zero) 4. Swap the positions of the maximum and minimum elements in the array. First, you need to find the maximum element as shown in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT