- 1

What's wrong with this?

#supposed to print LCM tell me what's wrong please comment. x=int(input()) y=int(input()) def lcm(x, y): if x>y: greater=x else: greater=y while(True): if((greater%x==0)and(greater%y==0)): lcm=greater break greater+=1 return lcm lcm(x,y)

9th Aug 2017, 5:03 PM
Mohammad Shihab
Mohammad Shihab - avatar
6 odpowiedzi
+ 7
Work on your indentation, man. You have to maintain the same indent jump everywhere.
9th Aug 2017, 5:15 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
@Prudhvi Raja correction seems right: the only line really bad indented is the 12th... ... but anyway, number of spaces (or tabs) is not mandatory to be 4: it's just had to be consistent (if you use n spaces for a block, you cannot mix tab but only n spaces, even 1 -- but it's rather recommanded to use more for readability ;P)
10th Aug 2017, 11:27 AM
visph
visph - avatar
+ 2
Python uses indentation (4 white spaces at the beginning of a line) to delimit blocks of code. Other languages, such as C, use curly braces to accomplish this, but in Python indentation is mandatory; programs won't work without it. For clarity check below code how each block is delimited. x=int(input()) y=int(input()) def lcm(x, y): if x>y: greater=x else: greater=y while True: if((greater%x==0)and(greater%y==0)): lcm=greater break greater+=1 return lcm print(lcm(x,y))
9th Aug 2017, 5:45 PM
⚛prudhvi⚛
⚛prudhvi⚛ - avatar
0
Yeah it's showing some indentation error
9th Aug 2017, 5:17 PM
Mohammad Shihab
Mohammad Shihab - avatar
0
can u plz explain
9th Aug 2017, 5:17 PM
Mohammad Shihab
Mohammad Shihab - avatar
- 1
if (condition): statement 1 elif(condition): stAtement 2 in c language or cpp statements that will be executed in loop or if else statement have to be enclosed by {} in python... u need to give indentation... and AS @ KUBA SAID... SAME INDENTATION JUMP
9th Aug 2017, 5:24 PM
sayan chandra
sayan chandra - avatar