作业帮 > 英语 > 作业

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

来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/17 06:07:39
Python练习
I have three kinds of fruit:
apple:$1.29/lb
grape:$2.29/lb
orange:$1.5/lb
\x05\x05\x05\x05\x05\x05
Which one do you want?
grape
Ok,grape.How many pounds do you want?
1.5
The cost is $3.44
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? \r\n')
weigt=raw_input('Ok, %s. How many pounds do you want? \r\n'%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
再问: 您好,请问cost输出时是怎样保留两位小数的?
再答: %.2f
再问: 能加一下您QQ吗,我刚学有些地方不太懂