print("请输入一个整数")
he = 0
i = 1
while i !=0 :
i = int(input())
he +=i
print(he)
print("请输入一个整数")
he = 0
if i = int(input()) !=0 :
he +=i
print(he)
print("请输入一个整数")
he = 0
i = 1
while i !=0 :
i = int(input())
he +=i
print(he)
print("请输入一个整数")
he = 0
if i = int(input()) !=0 :
he +=i
print(he)
40. while循环写法:
例如: while i<=10:print(i) i+=1
方法一:
he = 0
i = -1
while i != 0 :
i = int(input())
he += i
print(he)
这里在最开始给i赋值为-1,不影响循环,因为while里是用用户输入的覆盖了
自己的方法:
he = 0
print('input a number')
i = int(input())
while i != 0:
he += i
print('input a number')
i = int(input())
print(he)
这里的提示句可以直接写到input里,如input(’请输入一个数字:’)