python基礎之猜數字遊戲

 

 

#猜數字遊戲

import random   #impor語句導入random模塊

guessor=0;
print("#"*30)   #輸出30個」#「(」##############################「)用於裝飾輸出代碼,同下
print("hello! \nwhat is you name?")    #「\n」換行
print("#"*30)
Myname=input("please enter your name:")
print("*"*30)
print("hello {} \nlet's play game!".format(Myname))
print("*"*30)
number=random.randint(1,20) #調用random函數中的randit函數(用於生成指定範圍的隨機數)
print("well~"+Myname+",please guess the number between 1 and 2.\n")

print("You have six guesses.\n")


while guessor<=6:   #while循環(循環到知足條件爲止)
    print("tack a guess")
    guess=input("please enter your number:")
    print("^"*30)
    guess=int(guess)

    guessor=guessor+1

    if guess==number:
        print("good! your are right")
        break
    if guess<number:
        print("\ntoo low")
        print("%"*30)
    if guess>number:
        print("\ntoo big")
        print("%"*30)
print("\nYou've run out of guesses!")
相關文章
相關標籤/搜索