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 "+ 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:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值