Python Institute
Python Institute
Disclaimer
This exercise sheet is provided by the Python Institute for educational purposes. It is
designed to help you practice and master the fundamental concepts of Python
programming.
Instructions
1. This exercise is to be completed individually. Collaboration is not permitted.
2. Save your solutions in a Python file (.py). Name the file as:
YourName_PythonComprehensiveExercises.py
3. Submit the completed file to your instructor by the given deadline.
4. Use comments in your code to explain the purpose and logic of your solutions.
5. Your code should be clean, indented properly, and free of syntax errors.
6. Avoid using any external help or automated tools to solve the exercises. They are
designed to challenge and build your skills.
Part 1: Basics
1. Python Syntax
Write a Python script that:
1. Prints the message: "Welcome to Python Programming!".
2. Creates two variables: course with the value "Python Fundamentals" and
hours with the value 4.
3. Prints: "You are enrolled in <course> for <hours> hours."
4. Includes a comment explaining each line of your code.
2. Python Comments
Scenario: You are working on a Python project with a team. To make your code
readable, you need to use comments.
Write a Python script that includes:
o A single-line comment describing the purpose of the script.
o A multi-line comment listing three benefits of commenting in code.
Your script should also calculate and print the product of two numbers.
3. Python Variables
Scenario: You are creating a simple student database.
Write a Python script to:
1. Create variables to store a student’s:
Name (string)
Age (integer)
GPA (float)
Is enrolled (boolean)
2. Print each variable with a descriptive message.
3. Use comments to document why you chose specific data types for each
variable.
6. Python Strings
Scenario: You are building a program for a library to process book titles.
Write a Python script that:
1. Stores the book title "Harry Potter and the Philosopher's Stone" in a
variable.
2. Prints the title:
In uppercase
In lowercase
In title case
3. Extracts and prints:
The first 5 characters
The last 5 characters
4. Replaces the word "Philosopher's" with "Sorcerer's" and prints the
updated title.
8. Python If...Else
Scenario: You are writing software to assess exam grades.
Write a Python program that:
1. Asks the user to input their exam score (out of 100).
2. Checks if the score is:
Greater than or equal to 90: Print "Excellent"
Between 70 and 89: Print "Good"
Below 70: Print "Needs Improvement"
Bonus Challenge
Scenario: You are designing a simple text-based game.
1. Create a random number between 1 and 100 using random.randint().
2. Ask the user to guess the number.
3. Provide feedback for each guess:
o "Too high!" if the guess is greater than the number.
o "Too low!" if the guess is less than the number.
4. Continue until the user guesses the number correctly and print "You win!".