首页 > 编程语言 >TECH.UB.25: Intro to Python Programming

TECH.UB.25: Intro to Python Programming

时间:2024-10-18 20:43:22浏览次数:1  
标签:function Python drink Programming Intro user drinks called size

TECH.UB.25: Intro to Python Programming: Assignment # 4

Scenario:  Campus Pizza is really taking off and your co-founders love the programs you have built.  They want you to build an object-oriented program for their beverages.   Campus pizza has two beverage options: Soda from the soda fountain, and home-made lemonade which is available as sweetened or unsweetened.   Both beverages are $1.50 for a small, $1.75 for a medium and $2.00 for a large.  

Program Guidelines: 

1)Superclass: Create a superclass called “Beverage” that has two attributes: “size” and “price”.  “Beverage” should also have a method called “display” that prints out a statement of the size and price of the drink.  

2)Subclasses: 
a)Soda Subclass: Create a subclass “Soda” that inherits all the attributes and methods of Beverage.  
b)Lemonade Subclass: Create a subclass “Lemonade” that inherits all the attributes of subclass, but add an attribute called “sugar” for whether the customer wants the lemonade sweetened or unsweetened.  Additionally, edit the display function so that it also shows the sugar status.    
 
3)Functions: Outside of the classes, create the following functions:
a)Title: Create a function called “title” that prints the title “The Beverage Program”  
b)Closing: Create a function called “closing” that代 写TECH.UB.25: Intro to Python Programming  prints the number of drinks created and thanks them for using the program 
c)Getting Size:  Create a function called “get_size” that asks the user what size beverage the user wants (S, M, L) and assigns it to a variable called “size_input”.   If the user enters an invalid value, assume the size is a Small.  Based on their input, return a variable called “size” from the function. 
d)Get Sugar:  Create a function called “get_sugar” that asks the users who want a lemonade whether they would like their lemonade Sweetened or Unsweetened (S or U) and assigns it to a variable called “sugar_input”.  Return a variable called sugar with the phrase “Sweetened or Unsweetened” based on user status.  If the user doesn’t put an “S”, default to Unsweetened.   
e)Get Price:  Create a function called “get_price” that returns a variable called “price” based on the size of the drink.  

4)Main: 
-Nest all your functions inside a main function. 
-Start by creating an empty list called “drinks.”   
-Create a loop that allows the user to create orders for multiple drinks.  
- Ask the user to create a drink by asking for the drink type, “S” for soda, “L” for lemonade, “0” to exit, and then proceed to get the size of the drink.  (The reason this needs to be inside the main function vs. its own function is because the “0” will break the main program loop). 
- If the user enters an incorrect value for the drink type or size, end the program and ask them to run it again. 
- If the drink is a lemonade, ask the user if they would like it sweetened “S”  or unsweetened “U”.  If the user enters something else, assume it is unsweetened.  
- After the user has created all of the drink, assign it to an object.  Add this object to the “drinks” list.  
-When the user enters “0” and is done creating new drinks,  print all the objects in the “drinks” list.  For each drink in the list “drinks”, show the drink number, type, price and sweetness (for lemonades).  
-Finally, close the program and show the user the number of drinks they created.   

Program Console: 
______________________
The Beverage Program

Soda or a lemonade? Enter S, L or 0 for no drinks: S
What size would you like?  Enter S, M or L: M
Would you like to create another drink? y/n? y

Soda or a lemonade? Enter S, L or 0 for no drinks: Q
Incorrect drink type.  Please enter S or L: L
What size would you like?  Enter S, M or L: L
Sweetened or Unsweetened?  Enter S or U: U
Would you like to create another drink? y/n? y

Soda or a lemonade? Enter S, L or 0 for no drinks: L
What size would you like?  Enter S, M or L: S
Sweetened or Unsweetened?  Enter S or U: S
Would you like to create another drink? y/n? n

Drink 1: Soda
Size: Medium   Price: $1.75

Drink 2: Lemonade
Size: Large   Price: $2.00    Sugar: Unsweetened

Drink 3: Lemonade
Size: Small   Price: $1.50    Sugar: Sweetened

You created 3 drink orders. Thanks for using this program!

标签:function,Python,drink,Programming,Intro,user,drinks,called,size
From: https://www.cnblogs.com/goodlunn/p/18474707

相关文章

  • 学 Python 还是 Java 更好找工作?
    对于很多想进入编程领域的小伙伴来说,Python和Java这两门编程语言常常让人难以抉择。无论你是新手还是有经验的开发者,选择学习哪一门语言直接关系到未来的职业发展。那么,学Python还是Java更容易找到工作呢?近年来,随着AI、自动化、区块链等技术的崛起,Python的应用逐渐扩展到......
  • C - Word Ladder (Toyota Programming Contest 2024#9 (AtCoder Beginner Contest 370)
    题目链接:C-WordLadder题目:样例:分析:不要被题目所吓到,一切长题目都是纸老虎。题目大意就是给你两个字符串s和t,一次只能更换一个字母,求s变到t更换的次数,并输出每次更换一个字母后的最小字典序字符串。题意好理解,可以直接暴力,大力出奇迹。但是有没有更好的方法呢?既然问了......
  • (开题)flask框架求职招聘网站atjy7(程序+论文+python)
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容选题背景随着互联网技术的迅猛发展,信息传播方式发生了巨大变革。在就业领域,求职招聘的模式也从传统的线下模式逐渐向线上转移。传统的求职招聘方式......
  • 十四、Python基础语法(字符串str-下)
    一、字符串替换-replace语法:字符串.replace(old_str,new_str,count)将字符串中的old_str替换为new_str,count为替换的总次数,如果不写,表示全部替换,替换后返回一个完整的字符串,原来的不会改变。count为1,表示替换第一个值。my_str='testtestpython'#全部替换print......
  • 十二、Python基础语法(字符串str-上)
    一、定义字符串:使用单引号、双引号、三引号引用起的内容就是字符串。如果字符串本身包含引号时,要使用其他引号,也可以使用\转义,如果不想字符串中的字符进行转义,可以在字符串前面加上r。name1='python'name2="python"name3="""python"""name4='''python'''#如果......
  • Python 调用 FFMPEG
    Python调用FFMPEG从Python中调用FFMPEG不是很方便,只有通过subprocess或os.system等执行FFMPEG命令。也有ffmpeg-python这种已经封装好的三方库,但本着学习的目的,还是自己写了一个简单的Demo来实现获取视频信息和视频转码。Demo需要先下载FFMPEG的可执行文件放......
  • python - 分享绕过验证码登录的方法
    一、通过webdriver启动浏览器:二、添加cookie:三、切换到目标地址: #ThisisasamplePythonscript.fromseleniumimportwebdriverimporttime#PressShift+F10toexecuteitorreplaceitwithyourcode.#PressDoubleShifttosearcheverywhereforclas......
  • 使用Python和BeautifulSoup进行网页爬虫与数据采集
    目录一、什么是网页爬虫?1.1网页爬虫的应用场景二、爬虫的基本流程三、准备工作四、实战:抓取豆瓣电影Top2504.1发送请求4.2解析页面4.3数据存储五、应对反爬虫技术5.1使用代理5.2模拟浏览器行为六、爬虫的扩展与优化6.1处理分页6.2多线程爬取6.3动态......
  • 超简单的婴儿哭声检测实现方案--python版
    超简单的婴儿哭声检测实现方案--python版1.构建项目项目结构└─audio_data##音频文件├─mp3├─test└─wav##训练音频源文件每个目录代表不同的标签,自己定义和随意增加,cry目录存放的是婴儿的哭声├─cry├─non_cry└─other└─get-model.py└─main.py└......
  • gTTS: 强大的Python文本转语音库
    gTTSgTTS简介gTTS(GoogleText-to-Speech)是一个Python库和命令行工具,用于与GoogleTranslate的文本转语音API进行交互。它允许用户将文本转换为语音,并将结果保存为MP3文件或进行进一步的音频处理。gTTS支持多种语言,并提供了丰富的自定义选项,使其成为一个强大而灵活的文本转......