Search code examples
inputmultiplication

I'm trying to multiply the number of input statements by the number entered in a prior input statement


num1=input("How many days of weather do you have?")
num1=int(num1)

j = input("What is the rainfall for day1? \n")

b = num1

    print (j * b)

When the user inputs the days of weather they have, I want it to produce that number of input statements, and when they put in their inputs I'll use those numbers to get the total. My problem is when I run this it just multiplies whatever the j input is by num1, I want it to multiply the number of input statements by num1.


Solution

  • I think you are trying to fund the sum of the total number of days? In that case you need to add each entry.

    num1=input("How many days of weather do you have?")
    num1=int(num1)
    total=0
    for num in range(1,num1+1):
        j = input("What is the rainfall for day{}?".format(num))
        total+=int(j)
    
    print (total)