The Python Interactive Shell Classwork
The Python Interactive Shell Classwork

The Python Interactive Shell Classwork

CMS Sprint
CMS Unit
Item ID

Link to
Related to Content (1) (Production Pages)
Tags
Type
Worksheet
Lang
EN
Parent item
Sub-item
Sharable link for students

💡 You are welcome to jump into rooms in pairs and one of you shares their screen or work on your own. The choice is yours.

❓ Do I have Python installed?

Every mac comes with Python pre-installed. The version might be different for different macOS systems but for the purpose of this challenge it’s ok.

▶ How to open it?

‣
With PyCharm
‣
Through the mac terminal
‣

⌨ Keyboard Shortcuts Cheat Sheet

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!