本文主要是介绍09_Python终端控制的太空飞船,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我的学习笔记算是基于我所看的书本,所以名字只是个人爱好;
终端可做的事情:
飞向另一个星球;
发射跑炮弹;
打开汽锁;
自我毁灭;
密码保护;
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 "+ locationprint "Travelling to " + destinationtime.sleep(5) #飞向目的地所等待的时间;print "Arrived at " + destinationlocation = destinationelif 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:
这篇关于09_Python终端控制的太空飞船的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!