while True:
try:
a = int(input("please input:"))
print(a **2)
break
except: # 當輸入浮點數、漢字、字母等就會拋出異常。
print("sorry, please input again!")
while True:
try:
a = int(input("please input:"))
print(a **2)
break
except: # 當輸入浮點數、漢字、字母等就會拋出異常。
print("sorry, please input again!")
1.while循環的格式 while 條件: 條件滿足時,做的事情1 條件滿足時,做的事情2 條件滿足時,做的事情3 ...(省略)... demo