Home > Net >  5 repeats of a for loop multiplication
5 repeats of a for loop multiplication

Time:10-24

I'm a beginner at python, and have been given this task: Write a program that lets a user input numbers and have them multiplied. The user can use the program 5 times, then it should stop. Use at least a for loop and a function.

I believe the code here will ask for the numbers, multiply and give the answer, but how do I get it to run 5 times then stop asking for more numbers?

# get inputs
num1 = int(input('Enter first number: '))
num2 = int(input('Enter second number: '))

# calculate product
product = 0
for i in range(1,num2 1):
    product=product num1`  

# give answer
print("The Product of Number:", product)

CodePudding user response:

how do I get it to run 5 times then stop asking for more numbers?

  1. Get rid of the for i in range(1,num2 1) loop, since you don't need a loop in order to calculate the product of two numbers.
  2. Add a for i in range(5) loop at the very top of your code, and then indent everything under it 4 spaces to the right.
  • Related