+ 2

convert if to while

please help me. this code is using for, if and else. but how to make it just using while statement x=int(input("Number = ")) t=0 for i in range (0,x+1): if(i%2==1): t=t+1 if(i==x-1): print(i,end=" = ") else: print(i,end=" + ") print(t) please help:)

14th Oct 2016, 12:50 PM
Angel
Angel - avatar
3 Answers
+ 3
x = int(input("Number = ")) t = 0 i = 1 while i <= x: t += i if i < x-1: print(i, end=" + ") else: print(i, end=" = ") i += 2 print(t)
14th Oct 2016, 1:22 PM
Zen
Zen - avatar
0
x=int(input("Number = ")) t=0 for i in range (x+1,0,-1): if(i%2==0): t=t+1 if(i==2): print(i,end=" = ") else: print(i,end=" + ") print(t)
14th Oct 2016, 2:21 PM
Angel
Angel - avatar
0
how bout that?
14th Oct 2016, 2:21 PM
Angel
Angel - avatar