Write a program that asks the user to input a positive integer and then calculates and displays the factorial of the number. The program should call a function named getN

Answers

Answer 1

Answer:

The program is written in python and it doesn't make use of any comment;

(See explanation section for line by line explanation)

def getN(num):

     fact = 1

     for i in range(1, 1 + num):

           fact = fact * i

     print("Factorial: ",fact)

num = int(input("Number: "))

if num < 0:

     print("Invalid")

else:

     getN(num)

Explanation:

The function getNum is defined here

def getN(num):

Initialize the result of the factorial to 1

     fact = 1

Get an iteration from 1 to the user input number

     for i in range(1, 1 + num):

Multiply each number that makes the iteration

           fact = fact * i

Print result

     print("Factorial: ",fact)

Ths line prompts user to input number

num = int(input("Number: "))

This line checks if user input is less than 0; If yes, the program prints "Invalid"

if num < 0:

     print("Invalid")

If otherwise, the program calls the getN function

else:

     getN(num)


Related Questions

Other Questions
La camarera ________ la carta de bebidas en la mesa y pregunta a Federico y a m. Primero, yo quiero caf. Segundo, ________ Federico; l quiere agua. cuida; me toca a deposita; le toca a bebe; me levanta recoge; le levanta I think it is B but im not sure Explain the concept of "charge" and how it relates to electricity? Please help I will mark brainliest for correct answers! simplifica: 49/90, se puede???? What does President Lincoln express in the line in bold?A.AngerB.CertaintyC.DoubtD.Misery In the last stanza rain in summer, what is being compared with the leopards tawny hide? how to find the angel in trigonometry when all the lengths of the right angled triangle already given. The volume of a gas in a container varies inversely with the pressure on the gas. A container of helium has a volume of 370in3 under a pressure of 15psi (pounds per square inch). Write the equation that relates the volume, V, to the pressure, P. What would be the volume of this gas if the pressure was increased to 25psi? I need a paragraph on why classical music is better than modern! I need it for a debate! Before this wednesday! "The correct syntax for passing an array as an argument to a method when a method is called and an array is passed to it is: " Type the correct word in the boxes below. my your his her its our their 1. The boy likes________________ school. 2. Mary sees __________ mother every day. 3. My teachers bring___________ children to our place on Saturdays. 4. The cat eats _____________ food quickly. 5. I often forget _____________ key. 6. You write in __________book in class. 7. We bring ____________pencils to class. 8. The men always bring ______________wives to the party. 9. Mr Adams teaches_______________ class in the morning. 10. She likes to give presents to ___________________grandchildren. 11.They never do _______________homework. 12.Ali sometimes wear ____________green t-shirt. 13.We love ________________school. 14.Ayse and Ahmet play with __________________ sisters. 15.You always wear ______________uniform at school. Which expression is equivalent to In a game the average score was 60 time score was 5/2 of the average what was Tims score? Describe how people may develop prejudices. Lee watches TV for 2 hours per day. During that time, the TV consumes 150 watts per hour. Electricity costs (12 cents)/(1 kilowatt-hour). How much does Lee's TV cost to operate for a month of 30 days? Specter Co. has identified an investment project with the following cash flows. Year Cash Flow 1 $ 820 2 1,130 3 1,390 4 1,525 a. If the discount rate is 10 percent, what is the present value of these cash flows The key schedule results in generating multiple keys from the one secret key. These multiple keys are used: a. in multiple sessions of communications one after the other. For example, if someone has 12 keys, they can use it for twelve video calls one after the other. b. such that one of them is picked up at random at a time. c. some as private keys, some as public keys. d. for different rounds of encryption for the same plaintext to strengthen the cipher. Which of the following is false? Correlation coefficient and the slope always have the same sign (positive or negative). If the correlation coefficient is 1, then the slope must be 1 as well. If the correlation between two variables is close to 0.01, then there is a very weak linear relation between them. Correlation measures the strength of linear association between two numerical variables. Pleas answer this is in two minutes Read the lines from "Harlem."Maybe it just sagslike a heavy load.Read the lines from The Weary Blues."He did a lazy sway...He did a lazy sway.Which best describes the relationship between these lines?The lines from "Harlem" provide sensory details, and the lines from "The Weary Blues" do not.The lines from "Harlem" and the lines from "The Weary Blues" both provide details through personification.The lines from "Harlem" provide details using the sense of sight, and the lines from "The Weary Blues" providedetails using the sense of touch.The lines from "Harlem" and the lines from "The Weary Blues" both provide details using the sense of sight.MarathisandremSave and FyitThe answer is B on Edgenutity