Common Error

Forget to convert the type:

age = input("Enter age: ")
age = int(age)
while age < 12:
    print("No Entry. Children less than 12 cannot take the ride. ")
    age = input("Enter age: ")
    # Error! Missing code to convert string age to int
print("Please enter here for ride. Thank you."


Use the wrong type in comparison:

total = 0
i = input("Enter a number or -1 to exit: ")
i = int(i)
while i != '-1': # Error! Comparing int with string
    total = total + i
    i = input("Enter a number or -1 to exit: ")
    i = int(i)
    
print("the sum is "+str(total))


Last modified: Wednesday, 11 July 2018, 2:35 PM