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

Python之路DAY.1

时间:2018-06-09 00:03:13      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:inf   random   ant   game   invalid   ase   guess   密码   职业   

Python之路DAY.1

      第一阶段大概学习了python的基础,语法有while,if,for等,综合知识,我结合程序编写了以下内容,这是一个猜数游戏,需要注册登录然后猜数。缺点本人技术原因,每次进行都需要重新注册和登录。还请见谅。

知识整合:

#Author: Sam Zhang

print("Please register your information!")   #请注册你的信息
name=input("Name:")                                 #输入名字
age=int(input("Age:"))  #integer   把输入的转成整型
job=input("Job:")                           #输入职业
password=input("password:")                #输入密码
info=‘‘‘
------Welcome {name1} login!------
Name:{name1}
Age:{age1}
Job:{job1}
Password:{password1}
‘‘‘
.format(name1=name,
           age1=age,
           job1=job,
           password1=password)
print("----Sign in----")                       #登录
_name=input("You Name:")                        #登录名字
_password=input("Password:")                    #登录密码
if _name==name and _password==password:           #名字和密码相等
    
print(info)                                    #打印信息
    
print("Welcome to Guess GAME!","Range:1~100" )  欢迎来到猜数游戏,范围1~100
    
import random
    no1 = random.randrange(0, 100)  生成随机数NO1
    
count = 0
    while count < 3:                                                 #循环开始,3次
        
guess_no1 = int(input("Guess number:"))                    #输入猜测数
        
if guess_no1 == no1:
            print("Yes,you got it!")                              #猜中了
            
break
        elif 
guess_no1 > no1:
            print("Think smaller...猜小点")
        else:
            print("Think bigger...猜大点")
        count += 1
        if count == 3:
            countine_confirm = input("Do you want to keep guessing?")
            if countine_confirm != ‘n‘:                     #当输入的不是n,则继续。     !=    非语句
                
count = 0
else:
 

    print("Invalid username or password!")                  #错误的用户名或密码 

Python之路DAY.1

标签:inf   random   ant   game   invalid   ase   guess   密码   职业   

原文地址:https://www.cnblogs.com/sam-amateur/p/9157890.html

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