1. 程式人生 > >Python之路DAY.1

Python之路DAY.1

打印 入職 註冊 輸入 原因 for lse big 階段

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