今天是30天程式語言研究的第七天,研究的語言一樣是python,今天主要學習的是while和猜數字遊戲
網址:https://www.youtube.com/watch?v=zdMUJJKFdsU&ab_channel=GrandmaCan-%E6%88%91%E9%98%BF%E5%AC%A4%E9%83%BD%E6%9C%83
筆記:
i=1
while i<=5:
print(i)
i += 1 # i=i+1
print("迴圈結束") #print 1 2 3 4 5 迴圈結束
secret_num = 77
guess = None #預設為none
#沒限猜的次數
while secret_num != guess:
guess = int(input("請輸入數字: "))
if guess > secret_num:
print("小一點")
elif guess < secret_num:
print("大一點")
print("恭喜贏了")
#限定猜的次數
secret_num = 77
guess = None
guess_count =0
guess_limit = 3
out_of_limit = False
while secret_num != guess and not(out_of_limit):
guess_count += 1
if guess_count <= guess_limit:
guess = int(input("請輸入數字: "))
if guess > secret_num:
print("小一點")
elif guess < secret_num:
print("大一點")
else:
out_of_limit = True
if out_of_limit:
print("抱歉你輸了")
else:
print("恭喜你贏了")