变量
name = "xiaochui"
name2 = name
print("My name is",name2)
Myname is xiaochui
---------------------------------------------------------------------------------------------------------------
name = "xiaochui"
name2 = name name2直接指向"xiaochui" 不是先指向name
name = "xiao" name 覆盖了之前的变量,现在是"xiao", 而name2 还是"xiaochui"
print("My name is",name)
My name is xiao
-----------------------------------------------------------------------------------------------------------------
格式化输出
name = input("name:")
age = input("age:") 下面使用age:%d的话会报错,默认是字符串,而%d只能接收数字
sge = int (input("age:"))
job = input("job:")
salary = input("salary:")
info = ‘‘‘
-----------------------info of %s---------- # s==string
Name:%s
Age:%s
Age:%d #d只能接收数字,那么上面的age=input("age:")要修改,否则报错 age=int(input("age":))
Job:%s
Salary:%s
‘‘‘ %(name,name,age,job,salary)
print(info)
info2 = ‘‘‘
-----------------------info of {_naem}------------
Name = {_name}
Age = {_age}
Job = {_job}
Salary = {_salary}
‘‘‘ .format(_name = name,
_age = age,
_job = job,
_salart = salart)
print(info2)
------------------------------------------------------------------------------------------------------------------
密码看不了==密文
导入模块 import ****
import getpass
_username = "xiao"
_password = "chui"
username = input("username:")
password = input("password:")
if _username == username and _password == password:
print("Welcome user {name} login...".format(name= username))
else:
print("Invalid username or password!")
---------------------------------------------------------------------------------------------------------------------------
猜年龄
age_of_xiaochui = 18
count = 0
while True"
if count == 3:
break
guess_age = int(input("guess:"))
if age_of_xiaochui == guess_age:
print("yes,you got it!")
break
elif guess_age > age_of_xiaochui:
print("think samaller...")
else:
print("think bigger!")
count += 1
else:
print("you have tried too man yimes..fuck off")
不退出程序玩
age_of_xiaochui = 18
count = 0
while count <3:
guess_age = int(input("guess_age:")
if age_of_xiaochui == guess_age:
print("yes,you got it!")
break
esif guess_age > age_of_xiaochui:
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":
count = 0
else:
print("you have tried woo many yimes..fuck off")
------------------------------------------------------------------------------------------------------
forx循环
for i in range(10): # i 是临时变量
print("loop",i)
----------------------------------
age_of_xiaochui = 18
for i in range(3):
guess_age = int(input("guess_age:"))
if age_of_xiaochui == guess_age:
print("yes,you got it!")
break
elif guees_age < age_of_xiaochui:
print("think smaller...")
else:
print("think bigger!")
else:
print("you have tried too many yimes..fuck off")