try...except..
发现自己在尝试循环和try结合时出现了死循环,好可怕。
例子:将用户输入的数值进行统计
count = 0
total = 0
while True: #用它来直到用户输入done跳出
i_num = input("Enter a number:") #自己别忘了input()
if i_num == "done":break
try: #try来避免输入的是字符串
cover_num = float(i_num) #这一句不要写在try外面呀,try又傻了我
total= total + cover_num
count = count + 1
except:
print("not a number")
continue #提示完用户之后我用继续循环
print(count)
print(total)