码迷,mamicode.com
首页 > 编程语言 > 详细

python基础之猜数字游戏

时间:2019-11-16 19:27:38      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:input   换行   lease   you   orm   enter   imp   for   put   

 

 

#猜数字游戏

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!")

 

python基础之猜数字游戏

标签:input   换行   lease   you   orm   enter   imp   for   put   

原文地址:https://www.cnblogs.com/wangwenchao/p/11873000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!