This lab assignment is about learning the concept of value-returning functions, return values, sending and receiving multiple return values. It includes four problems: converting US dollar to Euro, choosing room type and meal plan, rewriting the program to have two return statements in each function, and comparing two numbers.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
_______________________________________________________________________ CSC121PYTHON PROGRAMMING _______________________________________________________________________ LAB 08FUNCTIONS [PART 2] OBJECTIVES In this lab assignment, students will learn: - What value-returning functions are and how to write them - What return values are and how to send and receive them - How to send multiple return values - How to receive multiple return values GOALS In this lab assignment, students will demonstrate the abilities to: - write value-returning functions - write code to send and receive return values - write code to send multiple return values - write code to receive multiple return values INSTRUCTIONANDPROBLEMS Write a Python program for each of the problems in this lab.You must organize your programs such that the input and output follows the format of the example output code you are given, if any is provided. Your variable names must follow either thecamel caseorunderscore convention, but not both in the same program.Also, their length should be 15 characters or less and preferably less than 12: A)Camel case (Java - like): •All variables contain either lowercase letters or numeric digits, except when there are multiple words in the variable name. Each word after the first must start with an uppercase letter. •Examples: a.number b.numStudents c.isValid B)Underscore (C++ - like):
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
______________________________________________________________________________________________________________________________________________________________________________________________________________________ CSC121Lab 08Page2 ______________________________________________________________________________________________________________________________________________________________________________________________________________________ •All variables contain either lowercase letters or numeric digits, except when there are multiple words in the variable name. Each word after the first must be separated by an underscore character. •Examples: a.number b.num_students c.is_valid Please use PyCharm to type and test your programs.Place all 4 Python program files (one for each problem) in afoldercalledLab08andzip up the folder as shown in the Course Resources document called CreatingSubmittingPythonPrograms.Submit theLab08.zipfile to Blackboard for credit. PROBLEM1 Write a program to convert US dollar to Euro.This program has two functions:mainand a value-returning functionconvert_to_euro.Please do the following: (a)In themainfunction,ask userto enter amount in US dollar. (b)In themainfunction, call theconvert_to_eurofunction and pass the amount in US dollar to it. (c)In theconvert_to_eurofunction, write code to convert US dollar to Euro.1 US dollar is equal to 0.88 Euro. Return the amount in Euro. (d)Themainfunctionreceives and displaysthe amount in Euro. The following is an example. Enter amount in US dollar: 100 Equivalent amount in Euro: 88.0 Save your Python program in a file namedP1.py. PROBLEM2 All freshmen of ABC College must live on campus.Single room is $3000 per semester, while double room is $2000 per semester.There are also two meal plans to choose.The 21-meal plan serves 21 meals each week with the price of $3500 per semester.The 15 mean plan serves 15 meals each week with the price of $2800 per semester. Write a program for a freshman to choose room type and meal plan.Define and use the following two functions:
______________________________________________________________________________________________________________________________________________________________________________________________________________________ CSC121Lab 08Page3 ______________________________________________________________________________________________________________________________________________________________________________________________________________________ choose_room: Display room types andget user choice.Display user choice. choose_meal: Display meal plans andget user choice.Display user choice. Each of these functions returns the price of the chosen item.You are allowed to write only onereturnstatement in each function.Set the price of the room or meal plan and then return the price. Write amainfunction to implement the mainline logic of the program. Calculate and displaythe total price in themainfunction. The following is an example. Single room: $3000 per semester Double room: $2000 per semester Enter 1 for single room, 2 for double room: 2 Double room chosen 21-meal per week: $3500 per semester 15-meal per week: $2800 per semester Enter 1 for 21-meal, 2 for 15-meal: 1 21-meal chosen Cost for room and board per semester: 5500 Save your Python program in a file namedP2.py. PROBLEM3 Rewrite your program in Problem 2.This time in the functionschoose_room andchoose_meal,you must have tworeturnstatements in each function.Instead of setting the price for each choice, just return the price. Save your Python program in a file namedP3.py. PROBLEM4 Write a program to do the following.Ask the user to enter two numbers. Compare them and display the larger one and the smaller one.Define and use the following functions: get_numbers:Ask user to entertwo numbers.Use areturnstatement to return them. large_small: Compare two numbers.Use areturnstatement to return the larger number and the smaller number
______________________________________________________________________________________________________________________________________________________________________________________________________________________ CSC121Lab 08Page4 ______________________________________________________________________________________________________________________________________________________________________________________________________________________ Also write amainfunction to implement the mainline logic.Call the get_numbersfunction to get two numbers.Then call thelarge_small function and pass the two numbers as arguments.Displaythe larger and the smaller numbers inmain. The following are two examples. Enter a number: 17 Enter another number: 20 The larger number is 20.0 The smaller number is 17.0 Enter a number: 15 Enter another number: 15 The larger number is 15.0 The smaller number is 15.0 Save your Python program in a file namedP4.py. GRADINGRUBRIC Writing and using main function [10 points] Writing and using other functions [15 points]