zoukankan      html  css  js  c++  java
  • Python 练习:简单的购物车

    salary = int(input("Please input your salary: "))
    msg = '''
    1. iphone6s 5800
    2. mac book 9000
    3. coffee   32
    4. python book 80
    5. bicyle   1500
    6. exit
    '''
    
    cart = []
    flag = True
    
    while flag:
        print(msg)
        tmp = int(input("what do you want to buy?"))
        if tmp == 1 and salary >= 5800:
            cart.append("iphone6s")
            salary = salary - 5800
            print("your balance is still has %d" %salary)
        elif tmp == 2 and salary >= 9000:
            cart.append("mac book")
            salary = salary - 9000
            print("your balance is still has %d" %salary)
        elif tmp == 3 and salary >= 32:
            cart.append("coffee")
            salary = salary - 32
            print("your balance is still has %d" %salary)
        elif tmp == 4 and salary >= 80:
            cart.append("python book")
            salary = salary - 80
            print("your balance is still has %d" %salary)
        elif tmp == 5 and salary >= 1500:
            cart.append("bicyle")
            salary = salary - 1500
            print("your balance is still has %d" %salary)
        elif tmp == 6:
            flag = False
        else:
            print("You don't have enough money")
    else:
        print("Your shopping cart has", cart)
  • 相关阅读:
    tensorflow之tf.squeeze()
    tf.slice()
    tensorflow之tf.meshgrid()
    tensorflow: arg_scope()
    tf.ConfigProto()
    os.path.join()
    argparse.ArgumentParser()用法解析
    Flutter学习之ListView(1)
    Flutter学习之image
    Flutter学习之image
  • 原文地址:https://www.cnblogs.com/klvchen/p/8577269.html
Copyright © 2011-2022 走看看