Reputation: 23
This script is supposed to ask for two numbers and output which number is larger, but keeps giving incorrect answers, such as 54>3514 and so on.
def numberThingy():
num1=input("Enter first number: ").strip()
num2=input("Enter second number: ").strip()
if num1>num2:
print("The first number is larger.")
elif num1<num2:
print("The second number is larger.")
else:
print("The numbers are equal.")
while True:
numberThingy()
Upvotes: 1
Views: 57
Reputation: 673
You need to cast int to the input. When input is given, it is a string by default. You also don't need the .strip() in this situation.
def numberThingy():
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
if num1>num2:
print("The first number is larger.")
elif num1<num2:
print("The second number is larger.")
else:
print("The numbers are equal.")
while True: numberThingy()
Upvotes: 2