Need help

Joined
Nov 2, 2023
Messages
2
Reaction score
0
I'm getting this error " input expected at most 1 argument, got 3"
my goal is this : I have a loop asking for the amount of rain in a month,I want it to ask for month 1 , month 2 so on and so on .

this is what I got


while index<=numYears:
numMonths=0
numMonths=float(input("Enter the number of months for recorded rainfall in year ", index , ":" ) )
 
Joined
Nov 2, 2023
Messages
2
Reaction score
0
I want it to say YEAR 1 , Year 2 , month 1 month 2 but I kept getting errors like listed above


index=1
totalsumMonths=0
totalrainfallAmount=0

while index<=numYears:
numMonths=0
numMonths=float(input("Enter the number of months for recorded rainfall in year: ") )
while numMonths <= 0:
numMonths=float(input("Try Again- Enter the number of months for recorded rainfall in year: "))

totalsumMonths += numMonths


count=1
totalrainFall=0


## Asking for the rain fall amount for the month

while count<=numMonths:
rainfall=float(input("Enter the rainfall amount for month: "))
totalrainFall += rainfall
totalrainfallAmount += rainfall
count+=1


avgyearlyRain= totalrainFall/numMonths
print ("YEAR REPORT: ")
print (" Total rainfall: " , format (totalrainFall,".2f") , "inches")
print (" Number of months: " , format (numMonths,".2f") ,"months")
print (" Average rainfall: " , format (avgyearlyRain,".2f") ,"inches")

index +=1
 
Joined
Jul 4, 2023
Messages
510
Reaction score
63
error " input expected at most 1 argument, got 3"

Python input() Function

Syntax​

input(prompt) - 1 argumen only

Parameter Values​

ParameterDescription
promptA String, representing a default message before the input.

try like this [ code on-line ]
Python:
index = 2

while True:
    try:
        numMonths = float(input(f"Enter the number of months for recorded rainfall in year {index}: "))
        if numMonths <= 0:
            print('The value entered must be greater than zero')
        else:
            break # User provided a valid value (number greater than zero) exit loop while
    except ValueError:
        print('Use only digits')
1698914466672.png



[ Efficient String Concatenation in Python ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top