Finding Errors


def the_flying_circus():
first=raw_input("Enter first number")
second=raw_input("Enter second number")
if first > second:
print "%s(first) is greater than %s(second)"%(first,second)
elif first < second:
print "%s(first) is smaller than %s(second)"%(first,second)
print "%s(first) is equal to %s(scond)"%(first,second)

Please tell me the error in this code..


When posting code, please properly format it so we can rule out indentation as the error.
Aside from that, I can see three problems:

  1. When using string formatting, don't include the variable straight after the %s. When you end it with % (first, second), it automatically assigns the variables in the order they are placed in the list.

  2. You're trying to compare two strings as if they were integers. To fix this, wrap each raw_input() with int(), which will make the variable an integer.

  3. When you apply what I stated in point 2, a new error will arise. In string formatting, %s works on variables set as strings. Because you've cast them to integers, you will need to change each %s to %d.

Hope this helped! If it did, please mark this answer as your solution. Thanks :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.