You are on page 1of 3

Worksheet 1.

2
INTRODUCTION TO PYTHON DS100-1
Name: APPLIED DATA SCIENCE
Vivien V. Villadelrey Page 1 of 3

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

Output

Write a code that will select and print “Data” from the following string:
2
Applied Data Science
Code

Output

Determine the volume (rounded to 2 decimal places) of a sphere with a radius 2 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

Output

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

Use indexing and slicing to create a sublist named triple_entente, which contains the first 3 countries (with the

This study source was downloaded by 100000847957315 from CourseHero.com on 06-10-2022 21:22:22 GMT -05:00 Page 1 of 3

https://www.coursehero.com/file/97037761/Worksheet-12docx/
corresponding capital cities) in the previous list. Print out this sublist.
Code

Output

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


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

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 20,000 and 30% for values 20,000 and above. Below is a sample
output:

6 Enter amount: 10000


Discount: 1000.0
Net Payable Amount: 9000.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

Output

Create a variable named count. Initialize this variable with the value 30. Write a while loop that lists the value of count
7
while its value is greater than 10. Decrease the value of count by 5 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

This study source was downloaded by 100000847957315 from CourseHero.com on 06-10-2022 21:22:22 GMT -05:00 Page 2 of 3

https://www.coursehero.com/file/97037761/Worksheet-12docx/
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

Output

This study source was downloaded by 100000847957315 from CourseHero.com on 06-10-2022 21:22:22 GMT -05:00 Page 3 of 3

https://www.coursehero.com/file/97037761/Worksheet-12docx/
Powered by TCPDF (www.tcpdf.org)

You might also like