IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> 外包 | A Menu-Driven Proram -> 正文阅读

[Python知识库]外包 | A Menu-Driven Proram

外包 | A Menu-Driven Proram

1. Question

Write a menu-driven program for De Anza College Food Court. (You need to use functions!)

  • Display the food menu to a user (Just show the 5 options’ names and prices - No need to show the Combos or the details!)
    在这里插入图片描述

  • Ask the user what he/she wants and how many of it. (Check the user inputs) AND use strip() function to strip your inputs(if needed)

  • Keep asking the user until he/she chooses the exit option.

  • Calculate the price.

  • Ask the user whether he/she is a student or a staff. There is no tax for students and a 9% tax for staff. Add the tax price to the total price.

  • Display the bill to the user. The bill includes:

    • The food items
    • The quantities
    • The cost of them
    • The total before tax
    • Tax amount
    • Total price after tax
      在这里插入图片描述
      ?

2. Code

  1. Burger Menu
    burger_Menu = [
       (5.25, 'De Anza Burger'), (5.75, 'Bacon Cheese'),
       (5.95, 'Mushroom Swiss'), (5.95, 'Western Burger'), (5.95, 'Don Cali Burger')
    ]
    
  2. show_menu()
    def show_menu():
        print('*' * 59)
        print('*%10s%s%10s*' % ('', 'Welcome to De Anza College Food Court', ''))
        print('*' * 59)
        print('%10s%+10s%+20s' % ('', 'Price', 'Item'))
        for i in range(len(burger_Menu)):
            print('%10s%d%+9s%+20s' % ('', i+1, '$'+str(burger_Menu[i][0]), burger_Menu[i][1]))
        print()
    
    在这里插入图片描述
  3. get_input()
    def get_input():
        food_Items = [0 for _ in range(len(burger_Menu))]
        while 1:
            input_Option = input('(6 for exit)Input your Option: ').strip()
            if input_Option not in '123456':
                print('*Excuse Me*: Please Input Option from 1 to 6')
                continue
            else:
                input_Option = int(input_Option)
                if input_Option == 6:
                    print("Thank you, hope to see you again!\n")
                    break
                else:
                    input_Num = input('How many you want: ').strip()
                    if input_Num.isdigit():
                        food_Items[input_Option-1] += int(input_Num)
                    else:
                        print('*Excuse Me*: Please enter an integer')
                        continue
        return food_Items
    
    在这里插入图片描述
  4. compute_bill()
    def compute_bill(food_Items):
        food_bill = [0 for _ in range(len(burger_Menu))]
        for i in range(len(food_Items)):
            food_bill[i] = burger_Menu[i][0] * food_Items[i]
        total_noTax = sum(food_bill)
        is_Student = input('Are you a student?(y/n): ').strip().lower()
        if is_Student == 'y' or is_Student == 'yes':
            tax = 0
        else:
            tax = total_noTax * 0.09
        total_withTax = total_noTax + tax
        return food_bill, total_noTax, tax, total_withTax
    
  5. print_bill()
    def print_bill(food_Items, food_bill, total_noTax, tax, total_withTax):
        print('\n*%20sHere is your bill%20s*' % ('', ''))
        print('%7s%-20s%-16s%-9s%10s' % ('', 'Item', 'Quantities', 'Cost', ''))
        for i in range(len(food_Items)):
            if food_Items[i] != 0:
                print('%7s%-20s%-16s%-9s%10s' % ('', burger_Menu[i][1], food_Items[i], '$'+str(food_bill[i]), ''))
            else:
                continue
        print()
        print('The total before tax: $%.2f' % total_noTax)
        print('Tax amount: $%.2f' % tax)
        print('Total price after tax: $%.2f' % total_withTax)
    
    在这里插入图片描述
  6. main()
    def main():
        show_menu()
        food_Items = get_input()
        if sum(food_Items) != 0:
            food_bill, total_noTax, tax, total_withTax = compute_bill(food_Items)
            print_bill(food_Items, food_bill, total_noTax, tax, total_withTax)
    

3. Sample Run 1

***********************************************************
*          Welcome to De Anza College Food Court          *
***********************************************************
               Price                Item
          1    $5.25      De Anza Burger
          2    $5.75        Bacon Cheese
          3    $5.95      Mushroom Swiss
          4    $5.95      Western Burger
          5    $5.95     Don Cali Burger

(6 for exit)Input your Option: 1
How many you want: 2
(6 for exit)Input your Option: 5
How many you want: 2
(6 for exit)Input your Option: 6
Thank you, hope to see you again!

Are you a student?(y/n): n

*                    Here is your bill                    *
       Item                Quantities      Cost
       De Anza Burger      2               $10.5
       Don Cali Burger     2               $11.9

The total before tax: $22.40
Tax amount: $2.02
Total price after tax: $24.42

Process finished with exit code 0

?

4. Sample Run 2

***********************************************************
*          Welcome to De Anza College Food Court          *
***********************************************************
               Price                Item
          1    $5.25      De Anza Burger
          2    $5.75        Bacon Cheese
          3    $5.95      Mushroom Swiss
          4    $5.95      Western Burger
          5    $5.95     Don Cali Burger

(6 for exit)Input your Option: abc
*Excuse Me*: Please Input Option from 1 to 6
(6 for exit)Input your Option: 9
*Excuse Me*: Please Input Option from 1 to 6
(6 for exit)Input your Option: 1
How many you want: 1.25
*Excuse Me*: Please enter an integer
(6 for exit)Input your Option: 1
How many you want: abc
*Excuse Me*: Please enter an integer
(6 for exit)Input your Option: 6
Thank you, hope to see you again!


Process finished with exit code 0
  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2022-05-11 16:25:25  更:2022-05-11 16:26:24 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/27 19:08:09-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计