If you have any questions, comments or issues with this project please post them here!
Hi Ian! I’m currently scratching my head at this error that python is throwing at me.
the error is " type error: “>=” not supported between instances of ‘int’ and ‘str’. here’s part of my code:
print (“guess the number challenge”)
count1 = 0
print (“pick a number between 0 and 100”)
number = int(input("what is your guess? > "))
if number >= “90” and number <= “100”:
print (“too high”)
count1 += 1
elif number >= “80” and number <= “89”:
print (“still too high”)
count1 += 1
The error is as the message states, Python cannot tell if a string is greater than or less than an integer.
Hence, this will cause an error:
if 1 > "1":
You will need to do:
if 1 > 1:
Your code should probably look like this:
print("guess the number challenge") print() count1 = 0 while True: print ("pick a number between 0 and 100") number = int(input("what is your guess? > ")) print() if number >= 90 and number <= 100: print ("too high") count1 += 1 continue elif number >= 80 and number <= 89: print ("still too high") count1 += 1 continue
By adding quotation marks (
") to the numbers you are comparing, you made them strings.
omg thank you so much!
@MattDESTROYER it’s past midnight and i think my brain is partly fried but thank you again! the program works as expected now
I would suggest getting some sleep then, it’s 11:30am on a Sunday for me lol.
Can you “Guess the Number” I have in mind ?
Day 18 of #Replit100DaysOfCode #100DaysOfCode.
Hiya, i just need help with this code:
I do not understand why the else statement is not working. The idea is , if the user inputs anything that isn’t a whole number, it should print “That is not a number” but i keep getting an error. My code is below:
Hi @dbpwygwhzy thanks for your post and welcome to the community!
The reason you see the error is because in line 7 the input is being converted into an integer, so it’s not even getting to the if statement.
You can stop the error from occurring by replacing line 7 with a
try... except block. For example:
guess = -1 while guess < 0: try: guess = int(input("Input the number ")) while guess < 1 or guess > 1000000: print("Enter a number between 1 and a million only.") guess = int(input("Input the number ")) except: print("That is not a number") guess = -1
You have also made separate
if statements, I believe you meant to make an
if chain, meaning those second two
if statements should become
elif statements. Otherwise the
else statement is only attached to the final
if statement as opposed to all of them:
# this forms one long chain of if conditions ending in an else condition if condition1: # ... elif condition2: # ... elif condition3: # ... else: # ...
# this is the equivalent of what you have if condition: # ... # not connected if condition: # ... # not connected if condition: # ... else: # ...