0% found this document useful (0 votes)
52 views5 pages

CHAVEZ, Jhonmar G.: Introduction To Python

This document contains 10 coding problems to practice Python concepts like functions, loops, conditionals, lists, and lambda functions. The problems involve tasks like getting user input, selecting substrings, calculating cylinder volume, creating and slicing lists, evaluating logical expressions, calculating discounts, using while loops, defining functions, exploring global and local scopes, and using lambda functions. The student is asked to write code for each problem, show the output, and answer additional questions testing their understanding.

Uploaded by

Jhonmar Chavez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views5 pages

CHAVEZ, Jhonmar G.: Introduction To Python

This document contains 10 coding problems to practice Python concepts like functions, loops, conditionals, lists, and lambda functions. The problems involve tasks like getting user input, selecting substrings, calculating cylinder volume, creating and slicing lists, evaluating logical expressions, calculating discounts, using while loops, defining functions, exploring global and local scopes, and using lambda functions. The student is asked to write code for each problem, show the output, and answer additional questions testing their understanding.

Uploaded by

Jhonmar Chavez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Worksheet 1.

2
DS100-2
INTRODUCTION TO PYTHON
APPLIED DATA SCIENCE
Name:

CHAVEZ, Jhonmar G. 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.

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

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


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

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:

Enter amount: 50000


Discount: 25000.0
Net Payable Amount: 25000.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

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)

What value is printed out when func1() is called? 2


What value is printed out when func2() is called? 10
What is the value of num in the global scope after calling both functions? 7

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

You might also like