Introduction To Python: Worksheet 1.2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

DS100-3

Worksheet 1.2
APPLIED DATA SCIENCE
INTRODUCTION TO PYTHON

Name:

Page 1 of 2

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.

Write a code that asks the user to enter three items: the applicant’s name, the officer’s name and the appointment time.
1 Use the inputs to create an output in this form:
<Officer> will interview <Applicant> at <time>.
Code and Output

Write a code that will select and print “Materials” from the following string:
2
School of Chemical, Biological and Materials Engineering and Sciences
Code and Output

Determine the volume (rounded to 2 decimal places) of a sphere with a radius 5 cm. The output should be of the following
format:
The volume of a sphere with a radius of <radius> is <volume> cm^3.
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

Create and print a list named powers which contains the following countries and their capital cities:
• England London
• France Paris
• Russia Moscow
• Austria Vienna
4
• Germany Berlin
• Italy Rome

Use indexing and slicing to create a sublist named triple_entente, which contains the first 3 countries (with the
corresponding capital cities) in the previous list. Print out this sublist.
Code and Output

Evaluate the following expression given that x = 2 and y = 7:


not(not(x < 1)) or not(y > 14 or y > 10)
5 A. True
B. False
C. Error

Page 1 of 2
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 10% for values below 80,000 and 30% for values 80,000 and above. Below is a sample
output:

6 Enter amount: 100000


Discount: 30000.0
Net Payable Amount: 70000.0

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

Create a variable named count. Initialize this variable with the value 50. Write a while loop that lists the value of count
7
while its value is less than 10. Decrease the value of count by 12 every time.
Code

Output

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:
8
‘<word1>!!!<word2>!!!<word3>!!!’
Code and Output

A variable num has been predefined as 5, alongside the following function definitions:

def func1():
num = 2
print(num)

def func2():
9 global num
double_num = num * 2
num = 7
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()?

Create a lambda function that returns the remainder when number1 is divided by number2. Print a test run of the
10
function.
Code and Output

Page 2 of 2

You might also like