+ 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:)
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)
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)
0
how bout that?