ProductsLogo
LogoStudy Documents
LogoAI Grader
LogoAI Answer
LogoAI Code Checker
LogoPlagiarism Checker
LogoAI Paraphraser
LogoAI Quiz
LogoAI Detector
PricingBlogAbout Us
logo

Functions in Python

Verified

Added on  2019/09/16

|4
|988
|573
Project
AI Summary
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.
Document Page
_______________________________________________________________________
CSC121 PYTHON PROGRAMMING
_______________________________________________________________________
LAB 08 FUNCTIONS [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
INSTRUCTION AND PROBLEMS
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 the camel case or underscore
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.
Document Page
______________________________________________________________________________________________________________________________________________________________________________________________________________________
CSC121 Lab 08 Page 2
______________________________________________________________________________________________________________________________________________________________________________________________________________________
• 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 a folder called Lab08 and zip up
the folder as shown in the Course Resources document called
CreatingSubmittingPythonPrograms. Submit the Lab08.zip file to
Blackboard for credit.
PROBLEM 1
Write a program to convert US dollar to Euro. This program has two
functions: main and a value-returning function convert_to_euro. Please do
the following:
(a) In the main function, ask user to enter amount in US dollar.
(b) In the main function, call the convert_to_euro function and pass the
amount in US dollar to it.
(c) In the convert_to_euro function, write code to convert US dollar to
Euro. 1 US dollar is equal to 0.88 Euro. Return the amount in Euro.
(d) The main function receives and displays the 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 named P1.py.
PROBLEM 2
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:
Document Page
______________________________________________________________________________________________________________________________________________________________________________________________________________________
CSC121 Lab 08 Page 3
______________________________________________________________________________________________________________________________________________________________________________________________________________________
choose_room: Display room types and get user choice. Display user
choice.
choose_meal: Display meal plans and get user choice. Display user
choice.
Each of these functions returns the price of the chosen item. You are
allowed to write only one return statement in each function. Set the
price of the room or meal plan and then return the price.
Write a main function to implement the mainline logic of the program.
Calculate and display the total price in the main function.
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 named P2.py.
PROBLEM 3
Rewrite your program in Problem 2. This time in the functions choose_room
and choose_meal, you must have two return statements in each
function. Instead of setting the price for each choice, just return the price.
Save your Python program in a file named P3.py.
PROBLEM 4
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 enter two numbers. Use a return statement
to return them.
large_small: Compare two numbers. Use a return statement to return
the larger number and the smaller number
Document Page
______________________________________________________________________________________________________________________________________________________________________________________________________________________
CSC121 Lab 08 Page 4
______________________________________________________________________________________________________________________________________________________________________________________________________________________
Also write a main function to implement the mainline logic. Call the
get_numbers function to get two numbers. Then call the large_small
function and pass the two numbers as arguments. Display the larger and
the smaller numbers in main.
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 named P4.py.
GRADING RUBRIC
Writing and using main function [10 points]
Writing and using other functions [15 points]
1 out of 4
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]