đĄ This is a group exercise, and itâs an opportunity to solve a problem together! Start with one team member sharing a screen with this page.
đ The Python Interactive Shell
For this exercise, weâll use the Python Interactive Shell.
How to open it?
- The interactive shell can be opened via PyCharmâs âTerminalâ tab at the bottom of the screen.
- In the Terminal tab, type
python3
on Mac orpython
on Windows to open the interactive shell. - You should see three arrows (
>>>
) indicating youâre in the Python interactive shell. - If you want to exit the interactive shell, you can type
exit()
at any time.
đâđŠș Assignment
You have here some challenges to solve, and the purpose is to solve them inside the interactive shell only.
Why canât I run the code normally via a file?
The interactive shell has its benefits - interactivity!
While you can technically run the exercise through a normal file, we want you to practice using the interactive shell.
𧥠Mini Challenge #1
You are working in a school, and youâre given a list of all grades in an exam.
grades = [10, 50, 60, 10, 50, 60, 30, 50]
- Copy this list and paste it into the interactive shell.
- Type
print(grades)
and see that you see the list of grades. - Type only
grades
and verify that you got the same result. - In the interactive shell, you donât need to
print
, as opposed to a regular file where you always have to print.
Assignment
- Print only the grades that passed the exam, i.e., got a grade above 60.
- Print âPASSEDâ for grades that have passed and âFAILEDâ for the rest, along with the grade itself.
- Print the grades with added 10% to every grade.
đ Mini Challenge #2
You got a list of websites:
websites = ["google.com", "youtube.com", "facebook.com", "twitter.com", "instagram.com", "baidu.com", "wikipedia.org","yandex.ru", "yahoo.com"]
- Print only the websites that end with .com.
- Print all the websites with .net instead of .com.
- Print only the website name capitalized without the extension (Output: Wikipedia, TwitterâŠ).
đ Mini Challenge #3
You are given a dictionary of restaurants and their ratings:
rest_rating = {
"McDonald's": 6,
"Foo": 10,
"Ramen": 8,
"Starbucks": 5
}
- Print all the names of the restaurants, along with their rating, in the format âFoo was rated 10â.
- Print only the restaurant names that got above 7.
- Delete the rating of âStarbucksâ.
đ Mini Challenge #4
Explore libraries with the Python interactive shell.
- Import the
random
module to the interactive shell by typingimport random
. - View the functions inside the module by typing
dir(random)
. - Choose a function that seems interesting to you. For example,
random.foo
(this function doesnât really exist). - Use the
help
command to read the documentation (in the interpreter) about the function:help(random.foo)
. - After you finish reading the documentation, you may need to press
q
to exit it. - Use the information that you read and use the function, to explore it.
- Feel free to explore more functions!