1. 程式人生 > >4、while循環練習

4、while循環練習

ons while循環 導致 pri oop don clas 何事 print

#從簡明Python搬來
number = 23
# 將23賦值給number的變量
running = True
# 在while語句運行前,將running變量設置為ture


while running:
    # 先檢查變量running是否為ture,然後再運行相應的塊
    guess = int(input(Enter an integer : ))

    if guess == number:
        print(Congratulations, you guessed it.)
        # 這將導致 while 循環中止
        running = False
    
elif guess < number: print(No, it is a little higher than that.) else: print(No, it is a little lower than that.) else: print(The while loop is over.) # 在這裏你可以做你想做的任何事 print(Done)

4、while循環練習