Page 1 of 1 CS107 M5 Assignments 1. Write a user-defined function volumeOfCone that receives two parameters of radius and height of a cone, and returns its volume. Also, write a program that prompts a...

1 answer below »
Computer Science using Python.


Page 1 of 1 CS107 M5 Assignments 1. Write a user-defined function volumeOfCone that receives two parameters of radius and height of a cone, and returns its volume. Also, write a program that prompts a message and lets the user input two real numbers for radius and height of a cone from the keyboard, and then the code will invoke the volumeOfCone function by passing the values of radius and height, and output the volume to the monitor. Hint: ? = ??2 ℎ 3 . Here, V is volume, r is radius, and h is the height. 2. Write a user-defined function factorial that receives a positive integer n and returns its factorial result (1*2*...*n), and then write a program to read an integer from the keyboard, calculate its factorial by calling the user-defined function, and output its factorial to the monitor. Using a loop, so the process could continue, an example as below. Read the number: 3 3! = 6 Continue (yes/no)? yes Read the number: -1 Invalid input. Try again. Read the number: 4 4! = 24 Continue (yes/no)? no 3. Write a user-defined function toKilometer that receives a value in miles (real number) and returns its corresponding value in kilometers. And then write a program to read a value in miles, convert it by calling the user-defined function, and output the corresponding value in kilometers to the monitor. Using a loop, so the process could continue. Formula from miles (m) to kilometer (k) is, k = 1.60934*m.
Answered Same DayNov 03, 2021

Answer To: Page 1 of 1 CS107 M5 Assignments 1. Write a user-defined function volumeOfCone that receives two...

Kondalarao answered on Nov 04 2021
115 Votes
factorial.py
def factorial(n):
fact = 1
for i in range(1, n+1):
fact = fact*i
return fact
loop = "yes"
while loop == "yes":
num = int(input('Read the number: '))
if num > 0:
print(num, "! = ", factorial(num))
else:
print("Invalid input. Try...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here