logo

Functions in Python

   

Added on  2019-09-16

4 Pages988 Words573 Views
 | 
 | 
 | 
_______________________________________________________________________CSC121PYTHON PROGRAMMING_______________________________________________________________________LAB 08FUNCTIONS [PART 2]OBJECTIVESIn 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 valuesGOALSIn 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 valuesINSTRUCTIONAND PROBLEMSWrite 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 underscoreconvention, 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.numberb.numStudentsc.isValidB)Underscore (C++ - like):
Functions in Python_1

______________________________________________________________________________________________________________________________________________________________________________________________________________________CSC121Lab 08Page 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.numberb.num_studentsc.is_validPlease use PyCharm to type and test your programs. Place all 4 Python program files (one for each problem) in a foldercalled Lab08and zip upthe folder as shown in the Course Resources document called CreatingSubmittingPythonPrograms. Submit the Lab08.zipfile to Blackboard for credit. PROBLEM 1Write a program to convert US dollar to Euro. This program has two functions: mainand a value-returning function convert_to_euro. Please do the following:(a)In the mainfunction, ask userto enter amount in US dollar.(b)In the mainfunction, call the convert_to_euro function and pass the amount in US dollar to it.(c)In the convert_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)The mainfunction receives and displaysthe amount in Euro.The following is an example.Enter amount in US dollar: 100Equivalent amount in Euro: 88.0Save your Python program in a file named P1.py.PROBLEM 2All 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:
Functions in Python_2

End of preview

Want to access all the pages? Upload your documents or become a member.