# 随机数的生成import random
die1 = random.randint(1,6)
die2 = random.randrange(6)+1
total = die1 + die2
print("You rolled a %d and a %d for a total of %d"%(die1,die2,total))
You rolled a 5 and a 4 for a total of 9
# if 语句print("Welcome to System Security Inc.")print("--where security is our middle name\n")
password =input("Enter your password:")if password =="lzq295406832":print("Acess Granted")input("\nPress the enter key to exit.")
Welcome to System Security Inc.
--where security is our middle name
Enter your password:zlq
Press the enter key to exit.
''
# if else语句print("Welcome to System Security Inc.")print("--where security is our middle name\n")
password =input("Enter your password:")if password =="lzq295406832":print("Access Granted")else:print("Access Denied")
Welcome to System Security Inc.
--where security is our middle name
Enter your password:lzq
Access Denied
#elif 语句import random
print("I sense your energy.Your true emotions are coming across my screen.")print("You are...")
mood = random.randint(1,3)if mood ==1:print("exciting")elif mood ==2:print("normal")else:print("sad")
I sense your energy.Your true emotions are coming across my screen.
You are...
exciting
#while循环print("\tWelcome to the 'Three-Year-Old Simulator'\n")print("This program simulates a conversation with a three-year-old child.")print("Try to stop the madness.\n")
response =""while response !="Because.":
response =input("Why?\n")print("Oh,Okay.")
Welcome to the 'Three-Year-Old Simulator'
This program simulates a conversation with a three-year-old child.
Try to stop the madness.
Why?
because
Why?
Because
Why?
Because.
Oh,Okay.
#将值作为条件print("Welcome to the Chateau D' Food")print("It seems we are quite full this evening.\n")
money =int(input("How many dollars do you slip the Maitre D?"))if money:#数字当作条件进行计算,0是False,其他是Trueprint("Ah,I am reminded of a table,Right this way.")else:print("Please,sit.It may be a while.")
Welcome to the Chateau D' Food
It seems we are quite full this evening.
How many dollars do you slip the Maitre D?0
Please,sit.It may be a while.
Exclusive Computer Networ
Members only!
Username:Lzq
Password:1996
Hi, Lzq
import random
print("This is a little game.")
number = random.randint(1,10)
guss =int(input("Please guss the number."))
tries =1while guss != number:print("You are wrong.")if guss > number:print("Higher...")else:print("Lower...")
guss =int(input("Please try again."))
tries +=1print("Lucily,the number is %d ,and you tried %d"%(number,tries))
This is a little game.
Please guss the number.5
You are wrong.
Lower...
Please try again.7
You are wrong.
Lower...
Please try again.9
Lucily,the number is 9 ,and you tried 3