207 Python Programming Exercises Volume 1 - Become A Pro Python Developer
207 Python Programming Exercises Volume 1 - Become A Pro Python Developer
Programming Exercises
Volume 1
207 Python
Programming Exercises
Volume 1
Edcorner Learning
Table of Contents
Module 1 Print Functions
Module 2 Calculations
Module 3 Slicing
Module 4 Data types in Python
Module 5 Strings
Module 6 Sets
Module 7: Tuples
Module 8 Lists
Module 9 Dictionaries
Module 10 – IF statements
Module 11 For loops
Module 12 Break Statements
Module 13 Continue Statements
Module 14 While loops
Module 15 Exception Handling
Module 16 Built-in functions
Module 17 Define Functions
Module 18 Lambda Expression
Module 19 Generators
Module 20 Set Comprehensive
Module 21 List Comprehension
Module 22 Dict Comprehension
Module 23 Built In Packages
Module 24 Final Mixed Exercises
Introduction
Python is a general-purpose interpreted, interactive, object- oriented, and a powerful programming
language with dynamic semantics. It is an easy language to learn and become expert. Python is one
among those rare languages that would claim to be both easy and powerful. Python's elegant syntax and
dynamic typing alongside its interpreted nature makes it an ideal language for scripting and robust
application development in many areas on giant platforms.
Python helps with the modules and packages, which inspires program modularity and code reuse. The
Python interpreter and thus the extensive standard library are all available in source or binary form for
free of charge for all critical platforms and can be freely distributed. Learning Python doesn't require
any pre- requisites. However, one should have the elemental understanding of programming languages.
This Book consist of 24 modules to practise different Python exercises on different topics.
In each exercise we have given the exercise coding statement you need to complete and verify your
answers. We also attached our own input output screen of each exercise and their solutions.
Learners can use their own python compiler in their system or can use any online compilers available.
We have covered all level of exercises in this book to give all the learners a good and efficient Learning
method to do hands on python different scenarios.
Module 1 Print Functions
1. Using the print () function, print to the console: 'Learn Python!'
Expected result:
'Learn Python!
print('Learn Python!')
2. Assign to the variable age number 20. Using the age variable and the
print() function print to the console the following text:
I am 20 years old.
3. Create two variables (you can freely choose the names) and assign to
them following values:
• ' Python’
• ’3.8'
Using these variables and the print () function, print to the console the
following text:
I am learning Python version 3.8
Expected result:
This costs 199.99
5. Assign 69.99 to the price variable and check the solution.
Expected result:
This costs 199.99
Coding :
price = 69.99
print(f'This costs {price}')
6. Assign two variables that store the following values:
• $ 34.99 - product price (float)
• 20 lbs - product weight (int)
Using the f-string formatting style print to the console the following message:
Price: $34.99. Weight: 20 lbs.
7. Below is an approximation of pi:
pt = 3.1415926535
Using f-string formatting, print the approximation of pi to two decimal places as shown below.
Expected result:
Pt: 3.14
8. Using three print () function (one line- one function) print the following text:
-------------------------------------------
VERSION: 1-0-1
-------------------------------------------
Tip: The lines consist of 40 dash characters ‘_’
9. Using the four print () function (one line - one function) print the following text:
==========================
author: edcorner learning
date: 01-01-2021
===========================
10. Using the print() function and the sep argument set to '#' print the following text:
‘summer#time#holiday’
Module 2 Calculations
11. Write a program that calculates the area of a circle with a radius = 5. Use an approximate
value of pi:
pt = 3.14
Print the result to the console as shown below.
Expected result:
Area: 78.5
12. Write a program that calculates the future value of 1000 USD with an annual interest rate of
3%, annual capitalization and a 5-year investment period. Round the result to the nearest
cent.
Tip: Use compound capitalization of interest.
Print the result to the console as shown below.
Expected result:
The future value of the investment: 1159.27 USD
13. Write a program that calculates the delta for the quadratic equation:
3x2 — 4x + 1 = 0
Print the result to the console as shown below.
Expected result:
Delta:
4
14. The arithmetic sequence is given with the following formula:
an = 10 + 4n
Calculate the sum of the first ten elements of this sequence. Print the result to the console as
shown below.
Expected result:
The sum
of the first 10 elements tn a sequence: 320.0
shown below.
Expected result:
16. Calculate the midpoint of the segment with ends at the points: A = (2,4), B = (-4,6) and
print
result to the console as shown below.
Expected result:
The middle point: (-1.0, 5.0)
Module 3 Slicing
17. From the given file name:
filename = 'view.jpg'
extract extension and print it to the console.
Expected result:
Jpg
Expected result:
<class 'str'>
<class 'str'>
<class 'str'>
<class ‘ NoneType'>
<class 'bool1>
<class 'str'>
is an instance of the bool class and print the result to the console.
Expected result:
True
Module 5 Strings
24. The following text is given:
text = 'python is a popular programming language.'
Use the appropriate method to replace the first letter of the text with uppercase. Print the result
to the console.
Expected result:
python is a popular programming language.
Expected result:
code1: True
code2: False
27. The following paths are given:
Path1 = 'youtube.com/watch’
path2 = 'google.com/search?q=car'
Using the appropriate method check if the paths refer to YouTube (e.g. start with ' youtube’).
Print the result to the console as shown below.
Expected result:
Path1: True
path2 : False
28. The following codes are given:
code1 = 'FVNISJND-20'
code2 = 'FVNISJND20'
Using the appropriate method, check whether the codes consist only of alphanumeric characters
(numbers + letters).
Print the result to the console as shown below.
Expected result:
Code1: False
code2 : True
https://www.edcredibly.com/s/store/courses/description/Programming-
and-Analytics-Courses-Yearly-Subscription
extract the slug after the last character ‘/’. Then replace all dashes with
spaces and print the result to the console as shown below.
Programming and Analytics Courses Yearly Subscription
Module 6 Sets
You may get a different order of items than the expected result.
42. Two customer ID sets are given. The first one tells you whether a
person clicked on the banner ad. Second, whether the person
purchased the product:
ts_clicked = {'9001', '9002', '9005'}
ts_bought = {'9002', '9004', '9005'}
Return the ID of those customers who clicked on the ad and bought the
product.
Expected result:
Customer ID: { '9002', '9005'}
Note: Remember that the set is an unordered data structure. You may get a
different order of
items than the expected result. You don't have to worry about it.
Module 7: Tuples
Nest these tuples into one tuple as shown below and print the result to the console.
Expected result:
(AAPL. US', 'IBM.US’, 'MSFT.US'). ('HD.US', 'Gs.US', 'NKE.US '))
['a', 'g', 'h', 'i', 'm', 'n', 'o', 'p', 'r', 't', 'y']
53. The following list is given:
filenames = ['vlew.jpg', 'bear.jpg', 'ball.png']
Add the file 'phone.jpg' to this list at the beginning. Then delete the file
'ball.png' . response, print the filenames list to the console.
Expected result:
['phone.jpg', 'view.jpg', 'bear.jpg']
54. The following list represents order ids for a given day:
dayl = ['3984', '9042', '4829', '2380']
Using the appropriate method, extend this list to the next day:
day2 = ['4231', '5234', '1345', '2455']
Print the result to the console.
Expected result:
Expected result:
Vienna
62. The following dictionary is given:
stocks = {
'MSFT.US': {'Microsoft Corp': 184}, ' AMAZ.US': {'Amazon Inc':
310},
'MMM.US': {'3M Co': 148}
Extract the value for the key 'amaz.us' and print it to the console.
Expected result:
{'Amazon Inc': 310}
63. The following dictionary is given:
stocks = {
'MSFT.US': {'Microsoft Corp': 184}, 'AAPL.US ' : {'Apple Inc': 310},
'MMM.US': {'3M Co': 148}
Get the price for Microsoft (value for the 'Microsoft corp' key) and print
it to the console.
Expected result:
184
Expected result:
11,22,44,55,77,88
79. The following list of numbers is given:
items = [1, 3, 4, 5, 6, 9, 10, 17, 23, 24]
Write a program that removes odd numbers and returns the remaining
ones. Print the result to the console.
Expected results:
[1, 5, 3, 2, 4]
81. The following text is given:
text = 'Python is a very popular programming language'
Write a program which extracts exactly the first four words as a list.
Standardize each word, i.e. replace uppercase letters with lowercase.
Present the result in a list and print to the console as shown below.
Expected result:
[0, 1, 0, 1, 1, 0]
84. Write a program that creates a histogram as a dictionary of the
following values:
items = ['x’, 'z’, ‘y’, 'x', 'y’, 'y’,' z’, 'x']
In response print histogram to the console.
Expected result:
{'X': 3, 'y': 4, ‘z’: 2}
Expected result:
['powerful', 'everywhere', 'friendly', 'reasons', 'anything']
Hello Bob!
Module 12 Break Statements
89. Write a program that compares two lists and returns True if the
lists contain at least one of the same element. Otherwise, it will
return False.
Use break statement in the solution and print result to the console.
Lists:
Listl = [1, 2, 0]
List2 = [4, 5, 6, 1]
Expected result:
True
92. The list of companies from the WIG.GAMES index is given with
the closing price and currency:
gaming = {
'11B’: [362.5, 'PLN1],
'CDR': [74.25, 'USD'],
'CIG': [0.85, 'PLN'],
'PLW: [79.5, 'USD'],
'TEN1: [300.0, 'PLN']
}
Using the continue statement, create a for loop that will change the
closing price from USD to PLN in this dictionary. Take USDPLN =
4.0.
In response, print the gaming dictionary to the console.
Expected result:
94. Write a program that prints to the console the first ten prime numbers separated by a
comma.
Tip: Use a while loop with break statement.
Expected result:
2,3,5,7,11,13,17,19,23,29
95. Using the while loop, calculate how many years you have to wait
for the return on the investment described below to at least double
your money (we only take into account full periods).
Description:
n - number of periods (In years)
pv - present value
r - interest rate (annual)
fV - future value
Investment parameters:
pv = 1000
r = 0.04
Print result to the console as shown below.
Expected result:
Future value: 2025.82 USD. Number of periods: 18 years
96. Use the stochastic gradient descent algorithm to find the
minimum ot the loss function given by the formula: L(w) = vv2 - 4w
The derivative of function L: 4^ = 2 * w—4
dw
Algorithm:
1. We start from the starting point, let's take:
W_0 = -1
2. We define in advance the maximum number of iterations:
max iters = 10000
3. We define a variable that will help us control the size of the step
towards the minimum, let’s set this value to 1:
previous_step_size = 1
4. We define the learning rate:
learning_rate = 0.01
5. We define the precision that is enough to find the minimum:
precision = 0.000001
6. We define the derivative of a function:
derivative = lambda w: 2 * w - 4
To find the minimum of the L function, move along the opposite
direction to the direction of the gradient by updating the value w_0
as follows:
w_0 = w_0 - learnlng_rate * derlvatlve(w_prev)
where w_prev is the point from the previous iteration. For the first
point is just w_0.
Create a while loop that will stop the algorithm when the minimum
is found with the precision we assumed or if we exceed the
maximum number of iterations. Print the result to the console as
shown below.
Tip: Conditions in a while loop:
while previous_step_size > precision and iters < max_iters:
Expected result:
A local minimum in point: 2.00
97. Write a program that checks if the given element (target) is in the
sorted list (numbers). We have given:
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] target = 7
Algorithm:
1. We set the start and end index as well as the flag = None .
2. As long as the start index is not greater than the end index, select
the middle index (mid) of the list (arithmetic average of the start and
end index -> remember to convert the result with the int ( ) function). If
the start index is greater than the end index, we end the algorithm.
3. Check if the element for the index calculated in this way is our
target. If so, we set the flag to True and terminate the algorithm. If not -
> step 4.
4. We check if the element of the list for the index mid is less than the
target. If so, we increase the start index by 1. If not, we reduce the end
index by 1 and go to step 2.
After while loop, depending on the value of the flag, print to the
console:
'Found' Or 'Not found' .
Expected result:
Found
Module 15 Exception Handling
98. Two variables defined below are given:
sum = 3000
counter = 0
We want to divide the variable sum by the counter variable. Using the
try... except... clause handle the ZeroDivisionError. If the division is
done correctly, print the result to the console, otherwise print to the
console the following message:
Expected Solution:
Division by zero.
True.
Solutions:
Solution:
def multi(numbers):
result = 1
for number in numbers:
result *= number
return result
def remove_duplicates(items):
return list(set(items))
def is_distinct(items):
return len(items) == len(set(items))
118. The following function is defined:
def function(idx, l=[]): for i in range(idx):
l.append(i ** 3) print(l)
Call the function three times as follows:
function(3)
function(5, ['a', 1b', 'c']) function(6)
Analyze the results!
Expected result:
[0, 1, 8]
['a', 'b', 'c', 0, 1, 8, 27, 64]
[0, 1, 8, 0, 1, 8, 27, 64, 125]
119. The following function is given:
def function(*args, **kwargs) print(args, kwargs)
Call the function in the order given:
function(3, 4) function(x=3, y=4)
function(l, 2, x=3, y=4)
Analyze the result!
Expected result:
(3, 4) {}
() {'x': 3, 'y': 4}
Expected result:
[(1, 4), (3, 4), (2, 5), (6, 1)]
Solution:
def file_gen(fnames):
for fname in fnames:
if fname.endswith('.txt'):
yield fname
131. Implement a generator called enum() that works just like the
enumerateQ built-in function. For simplicity, the function gets an
iterable object and returns a tuple (index, element).
Example:
[IN]: list(enum(['TEN', 'CDR1, 'BBT']))
[OUT]: [(0, 'TEN'), (1, 'CDR'), (2, 'BBT')]
Note! All you have to do is define a generator.
Solution:
def enum(items):
idx = 0
for item in items:
yield (idx, item)
idx += 1
133. Consider the two-roll of the dice. Create the probability space
(omega) and count the probability of getting a sum of points higher
than 10. Use set comprehension.
Expected result:
Probability: 0.08
135. Consider the two-roll of the dice. Create the probability space
(omega) and calculate the probability of getting a sum of squares
higher or equal to 45. Use set comprehension. Round the result to
two decimal places and print the result to the console as shown
below.
Expected result:
Probability: 0.22
136. Consider a three-roll of the dice. Create the probability space
(omega) and calculate the probability of obtaining three values
which the sum is divisible by 7. Use set comprehension. Round the
result to two decimal places and print the result to the console as
shown below.
Expected result:
Probability: 0.14
137. Calculate the probability that in three throws of symmetrical cubic
dice, the sum of the squares of points will be divisible by 3. Use set
comprehension. Round the result to the fourth decimal place and
print the result to the console as shown below.
Expected result:
Probability: x.xxxx
138. We roll the symmetrical dice three times. Calculate the probability
of the following:
• A - odd number of points in each roll
Use set comprehension. Round the result to three decimal places and
print to the console as shown below.
Expected result:
Probability: 0.125
Module 21 List Comprehension
140. The present value -pv and the investment period - n are given
below:
pv = 1000 n = 10
Depending on the interest rates given below, calculate the future value
fv of your investment:
rate = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07]
Round the result to the full cent and print the result to the console.
Expected result:
141. The present value -pv and the investment period - n are given
below:
pv = 1000 n = 10
Depending on the interest rates given below, calculate the value of
interest on investments:
rate = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07]
Round the result to the full cent and print the result to the console.
Expected result:
[104.62, 218.99, 343.92, 480.24, 628.89, 790.85, 967.15]
Formatted result:
[{1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9},
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7:49, 8: 64, 9: 81},
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512,
9: 729}]
148. The following list of indexes is given:
indeks = ['WIG20', 'mWIG40', 'sWIG80']
and a list of properties for each index:
properties = ['number of companies', 'companies', 'cap']
Using diet comprehension, create the following dictionary:
{'WIG20': {'cap': None, 'companies': None, 'number of companies':
None}
, 'mWIG40': {'cap': None, 'companies': None, 'number of companies':
None}
, 'sWIG80': {'cap': None, 'companies': None, 'number of companies':
None}}
Set the default value of each property to None and print the result to the
console.
Expected result:
{'WIG20': {'number of companies': None, 'companies': None, 'cap':
None}, 'mWIG40': {'number of companies': None, 'companies': None,
'cap': None}, 'sWIG80': {'number of companies': None, 'companies':
None, 'cap': None}}
149. The following list is given:
indexes = ['WIG20', 'nWIG40', 'sWIG80']
Using diet comprehension, convert the above list into the following
dictionary:
{0: 'WIG201, 1: ,nWIG40', 2: 'sWIG80'}
Print the result to the console.
Module 23 Built In Packages
150. Print the calendar for 2020 to the console using the calendar built-in module.
Expected result:
2021
Solution:
import calendar
print(calendar.calendar(2020))
151. Using the calendar built-in module, print a calendar for August 2021 to the console.
152.
Solution:
import calendar
print(calendar.month(2021, 8))
152. Using the datetime built-in module, calculate the difference for dates (date 2 - date 1):
date 1:2021-06-01
date 2: 2021-07-18
Print the result to the console as shown below.
Expected Result:
47 days, 0:00:00
153. Using the built-in module for regular expressions, find all digits in the following text:
string = 'Python 3.8'
Print the result to the console.
Tip: Use the findall() function and the regular expression '\d'
Expected result:
['3', '8']
154. Using the built-in module for regular expressions, find all alphanumeric characters in the
following text:
string = '!@#$%A&45wc'
Print the result to the console.
Tip: Use the findall()function and the regular expression '\w'
Expected result:
['4', '5', 'w', ’c']
155. Using the built-in module for regular expressions, find all email
addresses in the following text:
raw_text = "Send an email to contact@edcredibly.com or
'contact@edcorner.in"
Print the result to the console.
Tip: Use the findall() function and the regular expression * [\w\.-
]+@[\w\.-]+'
Expected Result:
['contact@edcredibly.com', 'contact@edcorner.in']
156. Using the built-in module for regular expressions, split the
following text by whitespace (spaces):
text = 'Programming in Python - from A to Z'
Print the result to the console.
Tip: Use the re.split() function and the regular expression '\s+' .
Expected result:
['Programming', 'in', 'Python', 'from', 'A', 'to', 'Z']
157. Using the string built-in module, print a string of lowercase and uppercase letters to the
console.
Expected result:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
158. Using the collections built-in package, create a Counter class
object that counts the frequency of items in the following list:
items = ['YES', 'NO', 'NO', 'YES', 'EMPTY', 'YES', 'NO']
Print the result to the console.
Expected result:
Counter({1 YES' : 3, 'NO': 3, 'EMPTY1: 1})
159. Using the math built-in module, implement the function called
sigmoid() expressed by the formula:
F(x) = 1/1+e-x
Note: All you have to do is implement the function.
Solution:
import math
def sigmoid(x):
return 1 / (1 + math.exp(-x))
160. Using the random built-in module set the random seed as follows:
random.seed(12)
And select randomly (pseudo-randomly) an item from the list below:
items = ['python', 'java', 'sql', 'c++', 'c']
Print the result to the console.
Expected result:
c++
161. Using the random built-in module set the random seed as follows:
random.seed(15)
And shuffle (pseudo-randomly) items in the following list:
items = ['python', 'java', 'sql', 'c++', 'c']
In response, print the list to the console.
Expected result:
['c', 'c++', 'sql', 'python', 'java']
162. Using the pickle built-in module, save the following list to the
data.pickle file.
ids = ['001', '003', '011']
Solution:
import pickle
ids = ['001', '003', '011']
with open('data.pickle', 'wb') as file:
pickle.dump(ids, file)
163. Using the json package, dump the following dictionary:
Stocks = {1PLW1: 360.0, 'TEN': 320.0, 'CDR': 329.0}
to the string, sorted by keys with indent 4. Print the result to the
console.
Expected result:
{
"CDR": 329.0,
"PLW": 360.0,
"TEN": 320.0
}
Module 24 Final Mixed Exercises
164. Consider the problem of binary classification in machine learning.
We have the following yjrue list with classes from the test set and
the following y_pred list with classes provided by the model:
y_true = [0, 0, 1, 1, O, 1, O] , y_pred = [0, 0, 1, 0, 0, 1, O]
Our task is to implement a function called accuracy( ) \ which takes two
arguments yjrue, y-pred and calculates the accuracy of our model. The
result is rounded to four decimal places. In response, call the function
on our data and print the result to the console.
Expected result:
0.8571
Solution:
def flatten(items):
result = []
for item in items:
result.extend(item)
return result
def transfer_zeros(items):
result = []
counter = 0
for item in items:
if item == 0:
counter += 1
else:
result.append(item)
result.extend([0] * counter)
return result
168. Implement a function called concatQ that accepts two lists in the
format given below:
u = [[1], [2]]
12 = [[3], [4]] and returns:
[[1, 3], [2, 4]]
Note: You only need to implement this function.
Solution:
Solution:
def identity(n):
array = [[0]*n for i in range(n)]
for idx, item in enumerate(array):
item[idx] = 1
return array
170. Implement a function called fill_value( ) that returns a two-
dimensional array of height x width and fills it with a fixed value.
Arguments:
height - natural number, height of the array
width - natural number, width of the array
value - the value to fill the array
Example:
[IN]: fill_value(height=2, width=3, value=255)
[OUT]: [[255, 255, 255], [255, 255, 255]]
[IN]: fill_value(4, 2, 'a')
[OUT]: [['a', 'a'], ['a', 'a'], ['a', 'a'], ['a', 'a']]
Note: You onlv need to implement this function.
Solution:
def fill_value(height, width, value):
return [[value] * width for i in range(height)]
171. Implement a function called trace( ) that returns the trace of the
matrix. The matrix must be a square matrix.
Argument:
• array - nested list (two-dimensional matrix)
Example:
[IN]: trace([[l]])
[OUT]: 1
[IN]: trace([[l, 2], [4, 2]])
[OUT]: 3
[IN]: trace([[3, 4, 5], [5, 2, 1], [5, 7, 2]])
[OUT]: 7
Note: You onlv need to implement this function.
Solution:
def trace(array):
total = 0
for idx, item in enumerate(array):
total += item[idx]
return total
def transpose(array):
width = len(array[0])
result = []
for i in range(width):
pair = []
for item in array:
pair.append(item[i])
result.append(pair)
return result
Solution:
def count_none(items):
counter = 0
for item in items:
if not item:
counter += 1
return counter
175. Given the code below, insert the correct method on line 3 to get
the index at which the substring Bitcoin starts.
my_string = "In 2010, someone paid 10k Bitcoin for two pizzas."
print(my_string.)
176. Given the code below, use the correct function on line 3 in order
to obtain the distance between num1 and 0.
num1 = -11
num2 =
177. Given the code below, use the correct function on line 4 in order
to raise num1 to the power of num2.
num1 = 10
num2 = 5
num3 =
print(num3 == 100000)
178. Given the code below, use the correct logical operator in between
the two expressions on line 1 in order for the final result to be False.
my_list.
print(my_list)
182. Given the code below, use the correct method on line 3 in order to
add the element 'C++' at the end of mylist.
my_list.
print(my_list)
183. Given the code below, use the correct method on line 3 in order to
remove the element 30 from mylist.
my_list = [10, 10.5, 20, 30, 'Python', 'Java', 'Ruby']
my_list.
print(my_list)
184. Given the code below, use the correct method on line 3 in order to
return the index of the element 10.5 in mylist.
index = my_list.
print(index)
185. Given the code below, use the correct method on line 3 in order to
insert the element 77 at index 4 in mylist.
my_list.
print(my_list)
186. Given the code below, use the correct method on line 3 in order to
concatenate mylist with [100, 101,102], by adding the latter at the
end of mylist.
my_list.
print(my_list)
187. Given the code below, use the correct method on line 3 in order to
find out how many times does the element 20 occur in mylist.
188. Given the code below, use the correct function on line 3 in order
to sort the elements of mylist in ascending order.
asc =
print(asc)
189. Given the code below, use the correct function (and argument) on line 3 in order to sort
the elements of mylist in descending order.
190.
asc =
print(asc)
191. Given the code below, use the correct function on line 3 in order
to find out the smallest number in mylist.
number =
print(number)
193. Given the code below, use the correct method on line 3 in order to
find out the index of Slovakia in my.tup.
index = my_tup.
print(index)
194. Given the code below, write code in order to perform tuple
assignment on line 3 and obtain the results below.
print(ro + ", " + po + ", " + es) #returns 'Romania, Poland, Estonia'
195. Given the code below, use the correct code on line 3 in order to
delete the key-value pair associated with key 3. Do not use a method
as a solution for this exercise!
print(crypto)
196. Given the code below, use the correct code on line 3 in order to
delete the key-value pair associated with key 3. This time, use a
method as a solution for this exercise!
print(crypto)
197. Given the code below, use the correct code on line 3 in order to
verify that 7 is not a key in the dictionary.
check =
print(check)
198. Given the code below, use the correct function on line 3 in order
to convert value to a string.
value = 10
conv =
print(type(conv))
199. Given the code below, use the correct function on line 3 in order
to convert value to an integer.
value = "10"
conv =
print(type(conv))
200. Given the code below, use the correct function on line 3 in order
to convert value to a floating-point number.
value = 10
conv =
print(type(conv))
201. Given the code below, use the correct function on line 3 to convert value to a list.
202.
value = "Hello!"
conv =
print(type(conv))
203. Given the code below, use the correct function on line 3 to convert
value to a tuple.
conv =
print(type(conv))
204. Given the code below, use the correct function on line 3 to convert value to a frozen
set.
205.
conv =
print(type(conv))
205. Given the code below, use the correct function on line 3 to convert
value to a binary representation.
value = 10
conv =
print(conv)
206. Given the code below, use the correct function on line 3 in order to convert value to a
hexadecimal representation.
207.
value = 10
conv =
print(conv)
207 Given the code below, use the correct function on line 3 to convert
value from binary to decimal notation.
value = '0b1010'
conv =
print(conv)
ABOUT THE AUTHOR
Edcredibly App –
https://play.google.com/store/apps/details?id=com.edcredibly.courses