Question
Q-Design a program called IntFun.py which reads in a non-negative integer from the user. The user will then be prompted with a menu of choices
Q-Design a program called IntFun.py which reads in a non-negative integer from the user. The user will then be prompted with a menu of choices (this menu should be repetitively displayed until the user chooses to quit): You must implement #1 and #5 and TWO of #2, #3,and #4. (SEE EXTRA CREDIT) Your menu will include these choices (stub out the one you dont implement.) 1. Enter a new number 2. Print the number of odd digits, even digits and zeros in the integer 3. Print the prime numbers between 2 and the integer 4. Print the sum of the digits of the integer 5. Quit the program PROGRAM PARTICULARS: When the program starts up, ask the user for a non-negative integer. After the user enters the non-negative integer, display the above menu. Remember the user can choose to do #2, #3, and #4 on the same number. Meaning, once you have the number from the user do not make the user enter a new number each time. The user can keep the same number until the user selects option 1 (see example output below.) There must be error checking on the input integer: if it is negative, the program will print an error message and re-prompt. This process will continue until valid input is entered. You may assume an integer of some form will be entered by the user.
print("Welcome to Integer Fun!")
integer = int(input("Please enter a non-negative integer ---> ")) while integer < 0: print("I am sorry that is not a non-negative integer.") integer = int(input(" Please enter a non-negative integer ---> "))
def main(): option = mainMenu()
while option != "5": if option == "1": newNumber() elif option == "2": function2() elif option == "4": print("function4 call here") option = mainMenu()
print("Thank you and have a nice day!")
def mainMenu(): select = "0" while select !="1" and select !="2" and select !="3" and select !="4" \ and select !="5": print("Please select an operation to perform:") print(" \ 1. Enter a new number \ 2. Print the number of odd, even, and zero(s) in the integer \ 3. Print the prime numbers between 2 and the integer \ 4. Print the sum of the digits of the integer \ 5. Quit Program") select = input(" Enter Your Option: ")
if select != "1" and select != "2" and \ select != "3" and select != "4" and select !="5": print("Invalid Option. Try again.")
return select def newNumber():
newNum = int(input("Please enter a new non-negative integer to begin: "))
return newNum
def function2():
even = [] odd = [] zero = [] for n in range(0,integer + 1): if n % 2 == 0: even.append(n) if n % 2 != 0: odd.append(n) for n in range(1,integer + 1): if str(n).endswith("0"): zero.append(n)
print( "{} has {} odd integer(s), {} even integer(s), and {} integer(s) have a zero.".format( str(integer),len(odd),len(even),len(zero)))
def function4(): print(even,odd,zero)
result = 0
for n in even: result += n for n in odd: result += n for n in zero: result += n print(result)
main()
The thing is my python code wont work!!! Any help would be greatly appreciated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started