+ 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)

19th Apr 2022, 11:21 AM
AARAV PANDEY
AARAV PANDEY - avatar
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")
19th Apr 2022, 3:17 PM
A͢J
A͢J - avatar
+ 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?
19th Apr 2022, 11:31 AM
Jayakrishna 🇮🇳
+ 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")
19th Apr 2022, 11:55 AM
SoloProg
SoloProg - avatar
+ 1
You didn't defined greater in the code and second thing: use ' ' for prompts
19th Apr 2022, 11:32 AM
JOKER
JOKER - avatar
+ 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")
19th Apr 2022, 3:44 PM
Mohamed Ayaou
+ 1
THANKS
20th Apr 2022, 1:18 AM
AARAV PANDEY
AARAV PANDEY - avatar