美文网首页
葡萄多少钱一斤?

葡萄多少钱一斤?

作者: 小糖豆儿er | 来源:发表于2020-07-08 14:40 被阅读0次

    胡歌老师这两天去监考了
    98上看到一个python
    凭借我3天的学习经验。。做出了一步。。

    题目:
    给定4种水果,分别是苹果、梨、橘子、葡萄,
    单价分别是3.0 元/公斤,2.5 元/公斤,4.1元/公斤,10.2元/公斤

    1. 首先在屏幕上显示以下菜单:
      [1]apple [2]pear [3] orange [4]grape
    2. 用户输入1-4查询对应水果的单价
    3. 连续查询超过5次,程序退出查询
    4. 输入不超过5次,但输入0时,程序退出查询
    5. 输入其他编号,显示0
    fruits=["[1]apple"," [2]pear"," [3] orange"," [4]grape "]
    print(' '.join(fruits)) #去掉外侧方括号
    print("\r") #换行
    price=["3","2.5","4.1","10.2"]
    number=int( input("the number of fruits"))
    if number==0:
        exit
    elif 1<=number<=len(fruits):
        print(fruits[number-1]+":"+price[number-1]+"r/kg")
    else:
        print(0)
    

    实现了1、2、4、5
    3?↓ 加while 计次

    fruits=["[1]apple"," [2]pear"," [3] orange"," [4]grape "]
    print(' '.join(fruits))
    price=["3","2.5","4.1","10.2"]
    a=0
    while a<5:
        number=int( input("the number of fruits: "))
        if number==0:
            break
        elif 1<=number<=len(fruits):
            print(fruits[number-1]+":"+price[number-1]+"r/kg")
        else:
            print(0)
        a=a+1 #这一行要在while里面!
    

    运行结果

    [1]apple  [2]pear  [3] orange  [4]grape 
    the number of fruits: 1
    [1]apple:3r/kg
    the number of fruits: 2
     [2]pear:2.5r/kg
    the number of fruits: 3
     [3] orange:4.1r/kg
    the number of fruits: 4
     [4]grape :10.2r/kg
    the number of fruits: 5
    0
    >>> 
    
    [1]apple  [2]pear  [3] orange  [4]grape 
    the number of fruits: 0
    >>> 
    

    相关文章

      网友评论

          本文标题:葡萄多少钱一斤?

          本文链接:https://www.haomeiwen.com/subject/onxccktx.html