+ 1
Why is this code showing error?
Why is this code showing error? This is my code :- num1=(int(input())) num2=(int(input())) if num1 is greater: print(num1 + is greater) if num2 is greater: print(num2 + is greater)
6 Answers
+ 5
Aarav Pandey
It's a program so you need to learn syntax.
num1 is greater => it's a sentence
(num1 > num2) => it's a syntax
Problem description says check which is greater value so here you have to use greater than syntax which is >
So
if num1 > num2:
print (num1 + "is greater")
else:
print (num2 + " is greater")
remember num1 and num2 are integer value so you cannot concat integer value with string value like that so you need to cast integer value with str function so above program should be:
if num1 > num2:
print (str(num1) + "is greater")
else:
print (str(num2) + " is greater")
+ 3
What is greater? It's undeclared
Strings should be enclosed in quotes " " or ' '
number + string is raise error.
what are you trying by this code?
+ 3
# Hope this code helps you
num1=int(input())
num2=int(input())
if num1 > num2:
print("num1 is greater than num2")
elif num1 < num2:
print("num1 is less than num2")
else:
print("num1 is equal to num2")
+ 1
You didn't defined greater in the code
and second thing: use ' ' for prompts
+ 1
wrong synthax.
this is the correct one:
num1=int(input())
num2=int(input())
if num1>num2:
print(num1 , "is greater")
if num1<num2:
print(num2 , "is greater")
+ 1
THANKS