我的学习笔记算是基于我所看的书本,所以名字只是个人爱好;
终端可做的事情:
飞向另一个星球;
发射跑炮弹;
打开汽锁;
自我毁灭;
密码保护;
1.新建文件;
2.变量声明,time模块引入;
3.输入程序:
import time
shipName = "Nastrama"
captain = "Wallace"
location = "Earth"
password = "Buttercups"
#密码检查:
pAttempt = raw_input("Enter the password: ")
while pAttempt != password:
print "Password incorrect"
pAttempt = raw_input("Enter the password: ")
print "Password correct.Welcome to the " + shipName
print ""
print "The spaceship " + shipName + " is currently visiting " + location + "."
choice = ""
while choice != "/exit":
print "What would you like to do, " + captain + "?"
print ""
print "a.Travel to another planet"
print "b.Fire cannons"
print "c.Open the airlock"
print "d.Self-destruct"
print "/exit to exirt"
print ""
choice = raw_input("Enter your choice: ")
if choice == "a":
destination = raw_input("Where would you like to go? ")
print "Leaving "+ location
print "Travelling to " + destination
time.sleep(5) #飞向目的地所等待的时间;
print "Arrived at " + destination
location = destination
elif choice == "b": #发射炮弹;
print "Firing cannons"
time.sleep(1)
print "BANG!"
time.sleep(1)
elif choice == "c":
print "Opening airlock"
time.sleep(3)
print "Airlock open"
time.sleep(1)
elif choice == "d": #飞船自我毁灭
confirm = raw_input("Are you sure you want the ship to self-destruct?(y/n)")
if confirm == "y":
print "Ship will self-destruct in"
print "3"
time.sleep(1)
print "2"
time.sleep(1)
print "1"
time.sleep(1)
print "Goodbye"
print "BOOM"
choice = "/exit"
elif choice == "/exit":
print "Goodbye"
else:
print "Invalid input. Please select a,b,c or d"
按下F5: