條件判斷與縮進(jìn),注意冒號(hào)
加次數(shù)限制
#猜數(shù)字
lucky_num = 19
input_num = -1
#次數(shù)限制
count = 0
#while lucky_num!=input_num and count < 3:
while count < 3:
input_num = int(input("please input your lucky_num:"))
if input_num < lucky_num:
print("please input big num")
elif input_num > lucky_num:
print("please input little num")
else:
print("great")
break
count += 1
print(count)
else:
print("too many counts!!!!")
注意縮進(jìn),python是對(duì)縮進(jìn)敏感的語言
注釋:ctrl+/
for循環(huán)
#次數(shù)限制
for i in range(3):
input_num = int(input("please input your lucky_num:"))
if input_num < lucky_num:
print("please input big num")
elif input_num > lucky_num:
print("please input little num")
else:
print("great")
break
else:
print("too many counts!!!!")