浙大Python 第4章-9 查询水果价格 (15 分)

原题题目

在这里插入图片描述



代码实现

print("[1] apple\n[2] pear\n[3] orange\n[4] grape\n[0] exit")
nums = list(input().split());prices = [3.00,2.50,4.10,10.20];strl,count = min(len(nums),5),0
while count<strl and nums[count] != '0':
    if 1<=int(nums[count]) <= 4:print("price = %.2f" % prices[int(nums[count])-1])
    else:print("price = %.2f" % 0)
    count+=1


提交结果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37500516/article/details/114393436