Python 父与子的编程之旅 第七章答案

7-1 商场促销

import easygui as gui
str_cost = gui.enterbox("the cost is ",title="super")
cost = float(str_cost)
if cost <= 10:
    gui.msgbox("原价="+ str_cost+"\n"+"折扣10%"+"\n"+"折扣价格="+str(cost*0.9))
elif cost > 10:
    gui.msgbox("原价=" + str_cost + "\n" + "折扣20%" + "\n" + "折扣价格=" + str(cost * 0.9))

7-2 足球队

import easygui as gui
age = 0
sex = gui.enterbox("tell me your sex:f or m")
if sex == 'f':
    age = int(gui.enterbox("input your age:"))
    if 10 <= age <= 12:
        gui.msgbox("join us")
    else:
        gui.msgbox("i am so sorry")
else:
    gui.msgbox("i am sorry,and we only need female")

7-3 加油站

import easygui as gui
tank = int(gui.enterbox("the tank container is :"))
percent = int(gui.enterbox("the percent of full is :"))
km = int(gui.enterbox("the km is :"))
distance = tank * percent / 100 * km
str2 = "size of tank :" + str(tank) + "\n" + "percent full" +str(percent) + "\n" + "km per liter" + str(km) + "\n"
if distance > 200:
    gui.msgbox( str2+ " you can go another %s km" %(str(distance)) + "\n" + "the next station is 200km far away"
                + "\n" + " you can wait for the next station")
else:
    gui.msgbox(str2 + "you must stop")

7-4 输入密码,you are in

import easygui as gui
code = 'mima123456'
tries = 0
test = gui.enterbox("请输入密码:",title="join us")
while test != code and tries < 5:
    if not test:
        break
    tries += 1
    test = gui.enterbox("please try again,you have %d times" %(5-tries))
    if(test == code):
        break
        
if (test == code):
    gui.msgbox("ok,you are in")
else:
    gui.msgbox("sorry")
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值