python while的用法(python输入整数n(n>=0),利用for循环和while循环求n)

2022-08-27 13:43:38
摘要:  python while的用法(python输入整数n(n>=0),利用for循环和while循环求n)...

xStart=raw_input("please enter the int number:")

xInt= int(xStart)

count=0

while not xInt==count:

count +=1

print count     #你输入多少就从1显示到这个数

还有就是求和:

xStart=raw_input("please enter the int number:")

xInt= int(xStart)

count= 0

sum= 0

while not xInt == count:

count += 1

sum += count   

print sum    

#这里显示的sum是如果你要输入数值5,则显示sum=1+2+3+4+5的值.