第一次python作业(快递价格计算、个人所得税计算、模拟银行存取款)
第一周python1、快递价格计算器:要求:提示用户输入:1、重量2、地点编号快递费算法:首重:3公斤3公斤以内:东三省/宁夏/青海/海南:12元新疆/西藏:20元港澳台/国外:不接受寄件其它:10元超过3公斤部分:东三省/宁夏/青海/海南:10元/公斤新疆/西藏:20元/公斤港澳台/国外:联系总公司其它:5元/公斤输入:1、重量2、地点编号输出...
·
1、快递价格计算器:
要求:
提示用户输入:1、重量 2、地点编号
快递费算法:首重:3公斤
3公斤以内:东三省/宁夏/青海/海南:12元 新疆/西藏:20元 港澳台/国外:不接受寄件 其它:10元
超过3公斤部分:东三省/宁夏/青海/海南:10元/公斤 新疆/西藏:20元/公斤 港澳台/国外:联系总公司 其它:5元/公斤
输入:1、重量 2、地点编号
输出:快递价格
area_name = ['0:东三省/宁夏/青海/海南','1:新疆/西藏','2:港澳台/国外','其他']
area_price = [12,20,'不接受邮寄','10']
area_overprice = [10,20,'联系总公司',5]
print(area_name)
def price_calculate():
if weigth<3:
if (int(area_code)==2):
print(area_price[area_code])
else:
print(area_price[area_code])
else :
if (int(area_code)==2):
print(area_overprice[area_code])
else:
print((weigth-3)*area_overprice[area_code]+area_price[area_code])
if __name__ == '__main__':
try:
weigth = int(input("please input the weigth:"))
area_code = int(input("please input your area code:"))
price_calculate()
except:
print("Parameter Error")
2、个人所得税计算器
def calculator():
salary = float(input("input your salary before tax:"))
if salary > 80000:
cal_salary = salary * 0.45 - 13504
elif salary > 55000:
cal_salary = salary * 0.35 - 5505
elif salary > 35000:
cal_salary = salary * 0.3 - 2755
elif salary > 9000:
cal_salary = salary * 0.25 - 1005
elif salary > 4500:
cal_salary = salary * 0.2 - 555
elif salary > 1500:
cal_salary = salary * 0.1 - 105
else:
i=6
cal_salary = salary * 0.03
print("纳税额:",cal_salary,"到手工资",salary-cal_salary)
if __name__ == '__main__':
try:
calculator()
except:
print("Parameter Error")
3、模拟银行存取款
1)模拟三张银行卡1001、1002、1003,分别设置密码和余额
2)提示用户输入银行卡密码
3)用户输入正确——提示选择:取款、存款、退出。并提示余额多少
用户输入错误——重新输入卡号密码
a.选择取款:提示输入取款额度,如果超过余额,提示余额不足,否则再余额上减去后显示余额
b.选择存款:输入存款额度,余额加上响应额度,并提示余额多少
c.选择退出:重新输入卡号和密码
4)设置三次输入错误账号密码,提示银行被锁定
class User():
def __init__(self,id,password,deposit):
self.id=id
self.password=password
self.deposit=deposit
def draw_money(self):
out_money=float(input("请输入取款金额:"))
if out_money>self.deposit:
print("余额不足")
else:
self.deposit-=out_money
print("您的余额是:", self.deposit)
def save_money(self):
save_money = float(input("请输入存款金额:"))
self.deposit+=save_money
print("您的余额是:",self.deposit)
def print_deposit(self):
print(self.deposit)
user_0 = User('1001','1001',1000)
user_1 = User('1002','1002',2000)
user_2 = User('1003','1003',3000)
user_list = (user_0,user_1,user_2)
def list_operate():
operate = [['0','取款'],['1','存款'],['2','退出']]
for i in operate:
print(i[0],i[1])
while (True):
try:
_user_id = input("请输入账号:")
_user_password = input("请输入密码:")
count=0
for i in user_list:
if (_user_id == i.id):
if (_user_password == i.password):
count=0
print("登陆成功")
list_operate()
operate_code = int(input('请输入您要进行的操作'))
while(operate_code != 3):
if (operate_code == 0):
i.draw_money()
list_operate()
operate_code = int(input('请输入您要进行的操作'))
elif (operate_code == 1):
i.save_money()
list_operate()
operate_code = int(input('请输入您要进行的操作'))
else:
print("退出登录")
break
else:
for j in range(3):
_user_password = input("密码错误,请重新输入密码:")
if(_user_password != i.password):
if (count == 2):
print("输入密码次数超过3次,账户锁定")
else:
count = count + 1
else:
break
except ValueError:
print("ValueError")
更多推荐
已为社区贡献1条内容
所有评论(0)