Python之路DAY.1

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!")                   # 错误的用户名或密码 

猜你喜欢

转载自www.cnblogs.com/sam-amateur/p/9157890.html