Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python TypeError?
#1
from random import randint
CorrectNumber = (1,20)
while True:
GuessedNumber = int(input("Guess a number between 1-20! "))
if GuessedNumber == CorrectNumber:
print("Correct, You Guessed the Number!")
break
elif GuessedNumber < CorrectNumber:
print("Too Low!")
continue
elif GuessedNumber > CorrectNumber:
print("Too High!")
continue
print("You Win!")


I am trying to make this guessing game, and i was attempting to improve it but now it says there is a TypeError in line 8,

Traceback (most recent call last):
File "<string>", line 8, in <module>
TypeError: unorderable types: int() < tuple()
Reply
#2
Please use python tags when posting code. See the BBCode link in my signature below for instructions.

CorrectNumber is not a number, it's a tuple of two numbers. You can't compare a tuple to a single number. I'm assuming you want to generate a random number, so line 2 should instead be:

CorrectNumber = randint(1, 20)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Yea i figured that out, lol I didn't see that i missed randint lol
Reply
#4
Dear Sir,
I am getting "'float' object is not callable (source id=1:0)" line 5 of the code. the code is posted below.

def _compute_distance(cls, rup, dists, alpha4_rrup, alpha4_sqrt_rrup, coeffs, ro2):
dist=0.0
for idist in xrange(len(alpha4_rrup)):
print alpha4_rrup[idist]
dist += coeffs['alpha3'](idist)*np.log(expi(alpha4_rrup(idist))-expi(alpha4_sqrt_rrup(idist)))/ro2
return dist
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020