Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Assessment#1 My biggest issue was creating a loop to cycle my program once executed so my users can restart within, rather than closing and re-launching it. I tested my loop() code which works on its...

1 answer below »
Assessment#1
My biggest issue was creating a loop to cycle my program once executed so my users can restart within, rather than closing and re-launching it. I tested my loop() code which works on its own, works with selecting the count down, but e
ors when running the factorial. Any insight?
print(" XXXXXXXXXXLoops & Functions---------------")
def countdown():
count_down = intege
while (count_down >= 0):
XXXXXXXXXXprint(count_down)
XXXXXXXXXXcount_down -= 1

def factorial():
global intege
factorial = 1
if integer < 0:
XXXXXXXXXXprint("Factorial will not define for a negative number")
elif(integer == 0):
XXXXXXXXXXprint("The factorial of 0 is 1")
else:
XXXXXXXXXXwhile(integer > 0):
XXXXXXXXXXfactorial = factorial * intege
XXXXXXXXXXinteger -= 1
print("factorial of the given number is: ")
print("-----------------------------------------------")
print(factorial)
integer = int(input("Please enter a number greater than 1: ")) #Enter your integere here with 1 or greate
print()
print('User selected:', integer)
print()
print('Please select the following option below:')
print ()
print('Option 1: Your integer will count down from', integer)
print ()
print('Option 2: Find the factorial of', integer)
print()
if integer < 0:
print("please enter number greater than zero")
elif(integer == 0):
print("Please enter number greater than 0")
else:
select = int(input("Please select an option: ")) #Select either options 1 or 2 by inputing numbers 1-2
if select == 1:
XXXXXXXXXXcountdown()
elif select == 2:
XXXXXXXXXXfactorial()
print("-----------------------------------------------")
print("Thank you for testing my Program! Good day!")
Loop Code:
def loop():
    repeat = input("Would you like to try again (Yes/No)? ").lower()
    if repeat == "yes":
        loop()
    else:
        print("Goodbye!")
        exit()
loop()
I started my process by defining the countdown and factorial functions, utilizing the while loop, if-else, and elif statements to compute and execute the countdown from whichever integer is inputted along with its factorial. I find it quite frustrating how particular Python is with spacing and that every variable is case-sensitive.
Assessment#2
I was able to set the definitions of counting down as well as the factorials. After trial and e
or, I started the program off with defining the two items. I them set two user inputs (one for the number, and the other for the option).  After the user inputs I put if options to determine how the inputs acted within the program. The only option I was struggling with and could not come up with is the negative number ending the program. I tried to understand this part and failed. If anyone has any suggestions or recommends another material I greatly appreciate. I look forward to hearing back from anyone.
#determine number to ente
x = ()
factorial = 1
#request number from end use
x = int(input("Please enter an integer (number) greater than 1:"))
#ask user which step to follow
selection = input ("Please enter 1 for a countdown or 2 to find the factorial:")
#print end user selection
if selection == "1":
    while x > 0:
        print (x)
        x = x - 1
elif selection == "2":
# check if the number is negative, positive or zero
    if x < 0:
        print ("Factorial does not exist for negative numbers")
    elif x == 0:
        print ("The factorial of 0 is 1")
    else:
        for i in range(1,x + 1):
            factorial = factorial*i
        print ("The factorial of",x,"is",factorial)
else:
    print ("Invalid Selection Entered")
Answered Same Day Mar 20, 2021

Solution

Pratap answered on Mar 20 2021
150 Votes
Assessment#1
Feedback and/or suggestions:
1. The user interaction which asks for a number at the beginning will happen only once all through the program. Include these interaction and validation in a new function, so that it becomes flexible enough to execute whenever necessary. Let this new function be called as “user_input” just for the reference.
2. Above created “user_input” function should be the main function of the program. That is the program should execute this function when it is executed.
3. Loop function: The basic functionality is to continue or exit on user wish.
· The query itself has a misleading guideline. The user will...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here