WS 1.2 Introduction To Python
WS 1.2 Introduction To Python
Write codes in Jupyter as required by the problems. Copy the code and output (as screen grab or screen shot) and paste them here.
Start a new number of a new page.
1 Date:
Write a code that asks the user to enter three items: the applicant’s name, the officer’s name and the appointment time. Use the
inputs to create an output in this form:
<Officer> will interview <Applicant> at <time>.
Code
Output
2 Date:
Write a code that will select and print “Data” from the following string:
Applied Data Science
Code
Output
3 Date:
Determine the volume (rounded to 2 decimal places) of a cylinder with height 200 cm and a circular base of radius 4.5 cm. the
output should be of the following format:
The volume of a cylinder with a height of <height> and a radius of <radius> 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
Output
4 Date:
Create and print a list named courses which contains a student’s previous quarter’s courses and grades:
Social Sciences 1.50
English 1.75
Economics 1.50
Computer Applications 1.25
Separations 1.75
Use indexing and slicing to create a sublist named gen_engg, which contains the first 3 courses (with the corresponding grades)
in the previous list. Print out this sublist.
Code
Output
Page 1 of 3
Name APPLIED DATA SCIENCE
5 Date:
Evaluate the following expression given that x = 8 and y = 9:
not(not(x < 3)) and not(y > 14 or y > 10)
A. True
B. False
C. Error
6 Date:
Create a code 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 10% for values
below 5,000 and 20% for values 5,000 and above. Below is a sample output:
Code
Output
7 Date:
Create a variable named count. Initialize this variable with the value 1. Write a while loop that lists the value of count while
its value is less than 20. Increase the value of count by 4 every time.
Code
Output
8 Date:
Create a function named three_shouts(), which has three parameters. This function returns strings concatenated with
‘!!!’. Call three_shouts(). The output should look like this:
‘Hi!!!Hello!!!Bye!!!’
Code
Output
Page 2 of 3
Name APPLIED DATA SCIENCE
9 Date:
A variable num has been predefined as 5, alongside the following function definitions:
def func1():
num = 3
print(num)
def func2():
global num
double_num = num * 2
num = 6
print(double_num)
What value is printed out when func1() is called?
What value is printed out when func2() is called?
What is the value of num in the global scope after calling func1() and func2()?
10 Date:
Create a lambda function that raises number to power pow. Print a test run of the function.
Code
Output
Page 3 of 3