Advertisement
Adehumble

Week4 Coding Exercise 5

Feb 22nd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #5
  2. #This program is very sensitive to user values. It is designed to keep asking for the right value in case a user enters a wrong input format without altering the program's execution.
  3.  
  4. def product(number_list):
  5.     product=1
  6.     for i in number_list:
  7.         product=product*i
  8.     print(product)
  9.  
  10.  
  11. user_number=[]
  12. while True:
  13.     try:
  14.         num=int(input("How many numbers do you wish to find their product? "))
  15.         break
  16.     except ValueError:
  17.         print("Oops! Thats not a number. Try again!")
  18.  
  19.  
  20. for i in range(0, num):
  21.     while True:
  22.         try:
  23.             element=int(input("Enter the numbers: "))
  24.             user_number.append(element)
  25.             break
  26.         except ValueError:
  27.             print("Oops! Thats not a number. Try again!")
  28.    
  29.  
  30. print("The product is: ")      
  31. product(user_number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement