0

m = (float(int("please put numbers"))) x=0 if x<=m: print (x) x+=2 else: print("exit")infinite loop what is wrong

19th Jan 2018, 4:44 PM
Mahmoud Essam
Mahmoud Essam - avatar
10 odpowiedzi
0
An if-structure isn't a loop. It's just to execute some code if a certain condition is true. In the code you originally posted the program will check if x<=m and then output x and do x+=2 once. The code in a while-loop will be executed until they condition at the beginning has become false, in your case if x becomes greater than they value inputed by the user.
19th Jan 2018, 5:57 PM
Jente
0
and how to put m as user want
19th Jan 2018, 4:46 PM
Mahmoud Essam
Mahmoud Essam - avatar
0
For giving m the value of input change the int into input. But i don't see a loop or isn't this the film code?
19th Jan 2018, 5:15 PM
Jente
0
i want to make a loop for example for even numbers but but i want a limit to stop as user want
19th Jan 2018, 5:33 PM
Mahmoud Essam
Mahmoud Essam - avatar
0
Ow i see, maybe you can work with a while-loop like this m = (float(input("please put numbers"))) x=0 while x<=m: print (x) x+=2 the loop will stop when x becomes bigger then the input value
19th Jan 2018, 5:40 PM
Jente
0
can you please teld me what is the deferent between if and while in simple way
19th Jan 2018, 5:42 PM
Mahmoud Essam
Mahmoud Essam - avatar
19th Jan 2018, 5:50 PM
Mahmoud Essam
Mahmoud Essam - avatar
0
thanks
19th Jan 2018, 5:50 PM
Mahmoud Essam
Mahmoud Essam - avatar
0
thanks very much
19th Jan 2018, 5:59 PM
Mahmoud Essam
Mahmoud Essam - avatar
0
no problem :)
19th Jan 2018, 6:06 PM
Jente