The Python Interactive Shell Classwork
The Python Interactive Shell Classwork

The Python Interactive Shell Classwork

💡 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?

  1. The interactive shell can be opened via PyCharm’s “Terminal” tab at the bottom of the screen.
  2. In the Terminal tab, type python3 on Mac or python on Windows to open the interactive shell.
  3. You should see three arrows (>>>) indicating you’re in the Python interactive shell.
  4. If you want to exit the interactive shell, you can type exit() at any time.
image

🐕‍đŸŠș 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]
  1. Copy this list and paste it into the interactive shell.
  2. Type print(grades) and see that you see the list of grades.
  3. Type only grades and verify that you got the same result.
    1. In the interactive shell, you don’t need to print, as opposed to a regular file where you always have to print.

Assignment

  1. Print only the grades that passed the exam, i.e., got a grade above 60.
  2. Print “PASSED” for grades that have passed and “FAILED” for the rest, along with the grade itself.
  3. 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"]
  1. Print only the websites that end with .com.
  2. Print all the websites with .net instead of .com.
  3. 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
}
  1. Print all the names of the restaurants, along with their rating, in the format “Foo was rated 10”.
  2. Print only the restaurant names that got above 7.
  3. Delete the rating of “Starbucks”.

💙 Mini Challenge #4

Explore libraries with the Python interactive shell.

  1. Import the random module to the interactive shell by typing import random.
  2. View the functions inside the module by typing dir(random).
  3. Choose a function that seems interesting to you. For example, random.foo (this function doesn’t really exist).
  4. Use the help command to read the documentation (in the interpreter) about the function: help(random.foo).
  5. After you finish reading the documentation, you may need to press q to exit it.
  6. Use the information that you read and use the function, to explore it.
  7. Feel free to explore more functions!