【Python】第3次练习:if条件语句——水费计算、判断闰年、货币转换程序(双符号)
程序员文章站
2022-03-15 18:14:32
...
【Python】第3次练习:if条件语句——水费计算、判断闰年、货币转换程序(双符号)
一、单选题:
二、程序题:
1、水费计算
w=eval(input())
if w<=10:
x=w*0.32
print('{:.1f}'.format(x))
if 10<w<=20:
x=(w-10)*0.64+10*0.32
print('{:.1f}'.format(x))
if w>20:
x=(w-20)*0.96+10*0.64+10*0.32
print('{:.1f}'.format(x))
2、判断闰年
y=eval(input())
if y%100!=0&y%4==0 or y%400==0:
print('True')
else:
print('False')
3、货币转换程序(双符号)
currency_string = input()
USD_rate=6.78
unit = currency_string[-1]
def convert_currency(money,exchange_rate):
output = money * exchange_rate
return output
if unit == 'D':
exchange_rate = USD_rate
money = eval(currency_string[:-3])
x=money * exchange_rate
a = '{:.2f}'.format(x)
print(str(a)+'RMB')
if unit == '$':
exchange_rate = USD_rate
money2= eval(currency_string[:-1])
x=money2 * exchange_rate
a = '{:.2f}'.format(x)
print(str(a)+'¥')
if unit == 'B':
exchange_rate = 1/USD_rate
money = eval(currency_string[:-3])
x = money * exchange_rate
a='{:.2f}'.format(x)
print(str(a)+'USD')
if unit == '¥':
exchange_rate = 1/USD_rate
money2 = eval(currency_string[:-1])
x = money2 * exchange_rate
a='{:.2f}'.format(x)
print(str(a)+'$')
上一篇: 上传第三方包到私服