I recently started learning python. I am trying to write a program using for or while loop that should categorize attendees at an event as "Beginner", "Novice", or "Expert" based on their years of work experience. It first asks the user for the number of attendees and then the years of experience of person 1, 2, 3, and so on up to the total number.
My code is:
n = int(input("Please enter the number of attendees: "))
for i in range(1,n 1,1):
experience = int(input("Please enter the years of experience of person",i))
if experience<=2:
print("Beginner")
elif 3<=experience<=5:
print("Novice")
elif experience>5:
print("Expert")
There is an error for the variable experience: raw_input() takes from 1 to 2 positional arguments but 3 were given
Any help is appreciated. Thank you.
CodePudding user response:
Use string formatting to substitute the person number into the prompt, you can't put it as a second argument to input()
.
experience = int(input(f"Please enter the years of experience of person {i}: "))
CodePudding user response:
in line 3 error experience = int(input("Please enter the years of experience of person",i)) the input function will take just one argument but you gave two arguments argument1="Please enter the years of experience of person" argument2=i to work this you must remove the second argument ie argument2 so the correct input function will be experience = int(input("Please enter the years of experience of person" str(i)))