155k views
0 votes
I tried making an if else statement in replit, and it keeps giving me this error:

this is my code:
print("Welcome, User.")
# ask for name, enter as variable
name = input("What would you liked to be called by?")
print("Hello, ."+name)
#ask user to enter number between 1-10, print user's name that amount of times
notr = input("Select a number from 1-10.")
if notr <= 10:
print(name)*notr
else:
print("Please enter a number following the constraints.")

the error seems to be in line 7 (if notr <= 10:) if you can help i would be grateful :)

I tried making an if else statement in replit, and it keeps giving me this error: this-example-1
User Morfioce
by
8.1k points

1 Answer

4 votes

Answer:

I think your error is in the line with the input statement asking for a number between 1-10. Input statements always take the input as a string, but on the next line you are trying to do an if statement with an integer. So you will have to cast the input from the input statement as an int. Below I have rewritten that line. Let me know if it worked!

notr = int(input("Select a number from 1-10 " )

User Yrstruly
by
8.5k points