Skip to content

Commit b17b33e

Browse files
committed
Updated exercises
1 parent fbb4a81 commit b17b33e

3 files changed

Lines changed: 166 additions & 114 deletions

File tree

Instructions/Exercises/01-create-a-personalized-greeting.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,29 @@ You'll write and run your code using an online Python editor — no installation
2626

2727
1. The editor may contain some default code. Select all of it and delete it so you're starting with a clean, empty file.
2828

29+
## Set up your program
30+
31+
Before writing any logic, you'll paste a set of guiding comments into the editor. These comments act as an outline for your program — each one marks where a specific piece of code belongs.
32+
33+
1. Copy the following comments and paste them into the editor pane:
34+
35+
```python
36+
# Display a welcome message
37+
38+
# Ask for the user's name
39+
40+
# Display a personalized greeting
41+
42+
# Ask for the user's favorite color and extend the greeting
43+
```
44+
45+
Remember, comments are ignored by Python when the program runs. They're just there to help you organize your code.
46+
2947
## Display a welcome message
3048

3149
The first thing your program should do is greet the user when it starts. You'll use the `print()` function to display a message on the screen.
3250

33-
1. In the editor pane, type the following code:
51+
1. In the editor pane, add the following line beneath the `# Display a welcome message` comment:
3452

3553
```python
3654
print("Welcome to the greeting program!")
@@ -48,9 +66,9 @@ The first thing your program should do is greet the user when it starts. You'll
4866

4967
## Ask for the user's name
5068

51-
Now you'll update the program to pause and ask for the user's name. The `input()` function displays a prompt and waits for the user to type a response.
69+
Now you'll add code that pauses the program and asks for the user's name. The `input()` function displays a prompt and waits for the user to type a response.
5270

53-
1. Add the following line below your existing code:
71+
1. Beneath the `# Ask for the user's name` comment, add the following line:
5472

5573
```python
5674
name = input("What is your name? ")
@@ -68,20 +86,12 @@ Now you'll update the program to pause and ask for the user's name. The `input()
6886

6987
Now you'll use the `name` variable to build a personalized message. You'll do this with an **f-string** — a string that can embed variable values directly inside it using curly braces `{}`.
7088

71-
1. Add the following line at the end of your code:
89+
1. Beneath the `# Display a personalized greeting` comment, add the following line:
7290

7391
```python
7492
print(f"Hello, {name}! It's great to meet you.")
7593
```
7694

77-
1. Your complete program should now look like this:
78-
79-
```python
80-
print("Welcome to the greeting program!")
81-
name = input("What is your name? ")
82-
print(f"Hello, {name}! It's great to meet you.")
83-
```
84-
8595
1. Run the program, enter your name when prompted, and press **Enter**.
8696

8797
1. You should see output similar to:
@@ -96,7 +106,7 @@ Now you'll use the `name` variable to build a personalized message. You'll do th
96106

97107
Let's make the greeting more personal by also asking for the user's favorite color and including it in the message.
98108

99-
1. Add two more lines below your existing code to ask for a favorite color and include it in a second message:
109+
1. Beneath the `# Ask for the user's favorite color and extend the greeting` comment, add the following two lines:
100110

101111
```python
102112
color = input("What is your favorite color? ")
@@ -106,9 +116,16 @@ Let's make the greeting more personal by also asking for the user's favorite col
106116
1. Your complete program should now look like this:
107117

108118
```python
119+
# Display a welcome message
109120
print("Welcome to the greeting program!")
121+
122+
# Ask for the user's name
110123
name = input("What is your name? ")
124+
125+
# Display a personalized greeting
111126
print(f"Hello, {name}! It's great to meet you.")
127+
128+
# Ask for the user's favorite color and extend the greeting
112129
color = input("What is your favorite color? ")
113130
print(f"Great choice! {color} is a wonderful color.")
114131
```
@@ -132,7 +149,7 @@ Using an AI assistant (like Copilot) is great way to explore a programming lang
132149
### Discovery 1: Create a decorative border
133150

134151
**AI Prompt:**
135-
> "In Python, how can I print 20 dashes in a row without typing them all out? Can you show me an example?"
152+
```In Python, how can I print 20 dashes in a row without typing them all out? Can you show me an example?```
136153

137154
**After the AI responds:** String repetition is a quick way to draw dividers or format output. Try running any examples the AI gives you in the online editor, and experiment with different characters and lengths.
138155

@@ -148,7 +165,7 @@ print("-" * 20)
148165
### Discovery 2: Transforming text
149166

150167
**AI Prompt:**
151-
> "In Python, how can I change a string input to all uppercase, all lowercase, or title case? Can you show me examples of each?"
168+
```In Python, how can I change a string input to all uppercase, all lowercase, or title case? Can you show me examples of each?```
152169

153170
***After the AI responds:** Look closely at the code examples it provides. Try modifying your greeting program to use one of these transformations on the user's name or favorite color.
154171

@@ -172,7 +189,7 @@ titlecase_name = name.title()
172189

173190
### Discovery 3: Printing punctuation
174191

175-
> "In Python, what happens if I try to print a string that contains a quote character inside it? How can I do that without causing an error?"
192+
```In Python, what happens if I try to print a string that contains a quote character inside it? How can I do that without causing an error?```
176193

177194
**After the AI responds:** Pay attention to the different ways it suggests for including quotes in strings. Try each method in the online editor and see how they work.
178195

Instructions/Exercises/02-calculate-students-gpa.md

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,31 @@ This exercise takes approximately **20** minutes.
2424

2525
1. Clear any default code from the editor so you're starting with a clean file.
2626

27+
## Set up your starter code
28+
29+
Before writing any logic, you'll paste a set of guiding comments into the editor. These comments act as an outline for your program — each one marks where a specific piece of code belongs.
30+
31+
1. Copy the following comments and paste them into the editor pane:
32+
33+
```python
34+
# Collect subject scores
35+
36+
# Display the entered scores
37+
38+
# Calculate the total, average, and GPA
39+
40+
# Display the results
41+
```
42+
43+
Remember, comments are ignored by Python when the program runs. They're just there to help you organize your code.
44+
45+
1. Leave the code as-is for now. In the steps that follow, you'll add code beneath each comment.
46+
2747
## Store grades as variables
2848

29-
You'll start by storing a student's subject scores as variables. Each score is a number out of 100.
49+
You'll start by storing a student's subject scores as hardcoded variables. Each score is a number out of 100.
3050

31-
1. In the editor pane, type the following code:
51+
1. Beneath the `# Collect subject scores` comment, add the following lines:
3252

3353
```python
3454
math_score = 88.0
@@ -39,7 +59,7 @@ You'll start by storing a student's subject scores as variables. Each score is a
3959

4060
Each variable holds a **float** — a decimal number. Even though some values like `88.0` could be written as whole numbers, using floats from the start ensures your calculations return accurate decimal results later.
4161

42-
1. Add a `print()` statement to confirm the values are stored correctly:
62+
1. Beneath the `# Display the entered scores` comment, add the following lines:
4363

4464
```python
4565
print("Scores entered:")
@@ -49,7 +69,7 @@ You'll start by storing a student's subject scores as variables. Each score is a
4969
print(f" History: {history_score}")
5070
```
5171

52-
1. Select the **▶ (Play)** button to run the program. You should see:
72+
1. Select the **▶ (Run Code)** button to run the program. You should see:
5373

5474
```output
5575
Scores entered:
@@ -59,55 +79,33 @@ You'll start by storing a student's subject scores as variables. Each score is a
5979
History: 83.5
6080
```
6181

62-
## Calculate the total and average
82+
## Calculate the total, average, and GPA
83+
84+
Now you'll use arithmetic to add up the scores, calculate the average, and convert it to a GPA on a 4.0 scale using the formula:
6385

64-
Now you'll use arithmetic to add up the scores and calculate the average.
86+
$$GPA = \frac{average}{100} \times 4.0$$
6587

66-
1. Add the following code below your existing print statements:
88+
1. Beneath the `# Calculate the total, average, and GPA` comment, add the following lines of code:
6789

6890
```python
6991
total = math_score + english_score + science_score + history_score
7092
num_subjects = 4
7193
average = total / num_subjects
94+
gpa = (average / 100) * 4.0
7295
```
7396

74-
1. Add a print statement to display the result:
97+
2. Beneath the `# Display the results` comment, add the following lines of code:
7598

7699
```python
77-
print(f"\nTotal score: {total}")
100+
print(f"\nTotal score: {total}")
78101
print(f"Number of subjects: {num_subjects}")
79-
print(f"Average score: {average}")
80-
```
81-
82-
> **Note**: `\n` inside an f-string adds a blank line before the text, which helps separate sections of output.
83-
84-
1. Run the program. The output should now include:
85-
86-
```output
87-
Total score: 339.0
88-
Number of subjects: 4
89-
Average score: 84.75
90-
```
91-
92-
## Convert the average to a GPA
93-
94-
GPA is typically reported on a 4.0 scale. You'll convert the percentage average using a simple formula:
95-
96-
$$GPA = \frac{average}{100} \times 4.0$$
97-
98-
1. Add the following line to perform the conversion:
99-
100-
```python
101-
gpa = (average / 100) * 4.0
102+
print(f"Average score: {average}")
103+
print(f"\nStudent GPA: {round(gpa, 2)} / 4.0")
102104
```
103105

104-
1. Display the final GPA, rounded to two decimal places using Python's built-in `round()` function:
106+
> **Note**: `\n` inside an f-string adds a blank line before the text, which helps separate sections of output. `round(gpa, 2)` rounds the GPA to two decimal places.
105107
106-
```python
107-
print(f"\nStudent GPA: {round(gpa, 2)} / 4.0")
108-
```
109-
110-
1. Run the program. Your complete output should now look like:
108+
3. Run the program. Your complete output should now look like this:
111109

112110
```output
113111
Scores entered:
@@ -116,18 +114,18 @@ $$GPA = \frac{average}{100} \times 4.0$$
116114
Science: 91.0
117115
History: 83.5
118116

119-
Total score: 339.0
117+
Total score: 339.0
120118
Number of subjects: 4
121-
Average score: 84.75
119+
Average score: 84.75
122120

123-
Student GPA: 3.39 / 4.0
121+
Student GPA: 3.39 / 4.0
124122
```
125123

126124
## Accept grades from user input
127125

128126
Hardcoded values are useful for testing, but a real program should accept input from the user. The `input()` function always returns a **string**, so you need to convert it to a `float` before you can use it in calculations.
129127

130-
1. Replace the four hardcoded score variables at the top of your program with `input()` calls that collect scores from the user:
128+
1. Replace the four hardcoded score variables beneath the `# Collect subject scores` comment with the following `input()` calls:
131129

132130
```python
133131
print("Enter scores out of 100 for each subject:\n")
@@ -142,23 +140,27 @@ Hardcoded values are useful for testing, but a real program should accept input
142140
1. Keep the rest of your code exactly as it is. Your complete program should now look like this:
143141

144142
```python
143+
# Collect subject scores
145144
print("Enter scores out of 100 for each subject:\n")
146145
math_score = float(input("Math score: "))
147146
english_score = float(input("English score: "))
148147
science_score = float(input("Science score: "))
149148
history_score = float(input("History score: "))
150149

150+
# Display the entered scores
151151
print("\nScores entered:")
152152
print(f" Math: {math_score}")
153153
print(f" English: {english_score}")
154154
print(f" Science: {science_score}")
155155
print(f" History: {history_score}")
156156

157+
# Calculate the total, average, and GPA
157158
total = math_score + english_score + science_score + history_score
158159
num_subjects = 4
159160
average = total / num_subjects
160161
gpa = (average / 100) * 4.0
161162

163+
# Display the results
162164
print(f"\nTotal score: {total}")
163165
print(f"Number of subjects: {num_subjects}")
164166
print(f"Average score: {average}")
@@ -167,7 +169,7 @@ Hardcoded values are useful for testing, but a real program should accept input
167169

168170
1. Run the program. When each prompt appears in the output terminal, click on it, type a score, and press **Enter**.
169171

170-
1. Try entering the same values as before to verify your output matches the hardcoded version:
172+
2. Try entering the same values as before to verify your output matches the following:
171173

172174
```output
173175
Enter scores out of 100 for each subject:

0 commit comments

Comments
 (0)