Python练习I have three kinds of fruit:apple:$1.29/lbgrape:$2.2

Python练习
I have three kinds of fruit:
apple:$1.29/lb
grape:$2.29/lb
orange:$1.5/lb
x05x05x05x05x05x05
Which one do you want?
grape
Ok,grape.How many pounds do you want?
1.5
The cost is $3.44
danqingZ 1年前 已收到1个回答 举报

jason_zjm 幼苗

共回答了21个问题采纳率:90.5% 举报

print '''
I have three kinds of fruit:
apple: $1.29/lb
grape: $2.29/lb
orange: $1.5/lb
'''
name=raw_input('Which one do you want? rn')
weigt=raw_input('Ok, %s. How many pounds do you want? rn'%name)
if name=='apple':
price=1.29*float(weigt)
elif name=='grape':
price=2.29*float(weigt)
elif name=='orange':
price=1.5*float(weigt)

print 'The cost is $%.2f'%price

1年前 追问

1

danqingZ 举报

您好,请问cost输出时是怎样保留两位小数的?

danqingZ 举报

能加一下您QQ吗,我刚学有些地方不太懂
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.563 s. - webmaster@yulucn.com