- 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)
6 Answers
+ 7
Work on your indentation, man. You have to maintain the same indent jump everywhere.
+ 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)
+ 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))
0
Yeah it's showing some indentation error
0
can u plz explain
- 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