CHAVEZ, Jhonmar G.: Introduction To Python
CHAVEZ, Jhonmar G.: Introduction To Python
2
DS100-2
INTRODUCTION TO PYTHON
APPLIED DATA SCIENCE
Name:
Write codes in Jupyter notebook as required by the problems. Copy both code and output as screen grab or screen shot and paste
them here.
1 Write a code that asks the user to enter three items: the course title, the textbook, and the assigned book’s author. Use the
inputs to create an output in this form:
The textbook for the course <Course title> is <Instructor> by <room>.
Code and Output
2 Write a code that will select and print “Phil” from the following string:
Republic of the Philippines
Code and Output
3 Determine the volume (rounded to 2 decimal places) of a cylinder with a circular base of radius 2 cm and a height of 8 cm.
The output should be of the following format:
The volume of a cylinder with a radius of <radius> and a height of <height> is
<volume> cm^3.
Note: Use math.pi for the pi constant. To use the math package, include the following code prior to your lines:
import math
Code and Output
Page 1 of 5
4 Create and print a list named provinces which contains the following provinces and their capital cities:
• Aurora Baler
• Bataan Balanga
• Bulacan Malolos
• Laguna Sta. Cruz
• Oriental Mindoro Calapan
• Batangas Batangas City
Use indexing and slicing to create a sublist named central_luzon, which contains the first 3 provinces (with their
corresponding capital cities) in the previous list. Print out this sublist.
Code and Output
Page 2 of 5
6 Create a code (that is both effective and efficient) that asks the user to enter a sales amount. The code should calculate the
effective discount based on the entered sales amount and the net payable amount, which is the original amount less the
discount. Let the discount rate be 20% for values below 50,000 and 50% for values 50,000 and above. Below is a sample
output:
Note: run the code the minimum number of times to make sure that the code does not return any logical errors. Show the
output of all these runs.
Code and Output
Page 3 of 5
7 Create a variable named count. Initialize this variable with the value 30. Write a while loop that lists the value of count
while its value is greater than 10. Decrease the value of count by 3 every time.
Code and Output
8 Create a function named three_words(), which has three parameters. This function returns strings concatenated with
‘!!!’. Call three_words(). The output should look like this:
‘<word1>!!!<word2>!!!<word3>!!!’
Code and Output
Page 4 of 5
9 A variable num has been predefined as 5, alongside the following function definitions:
def func1():
num = 2
print(num)
def func2():
global num
double_num = num * 2
num = 7
print(double_num)
10 Create a lambda function that determines the integer part (only the integer part) of the quotient when number is divided
by divisor. Print a test run of this lambda function.
Code and Output
Page 5 of 5