You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Instructions/Exercises/01-create-a-personalized-greeting.md
+33-16Lines changed: 33 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,11 +26,29 @@ You'll write and run your code using an online Python editor — no installation
26
26
27
27
1. The editor may contain some default code. Select all of it and delete it so you're starting with a clean, empty file.
28
28
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
+
29
47
## Display a welcome message
30
48
31
49
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.
32
50
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:
34
52
35
53
```python
36
54
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
48
66
49
67
## Ask for the user's name
50
68
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.
52
70
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:
54
72
55
73
```python
56
74
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()
68
86
69
87
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 `{}`.
70
88
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:
72
90
73
91
```python
74
92
print(f"Hello, {name}! It's great to meet you.")
75
93
```
76
94
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
-
85
95
1. Run the program, enter your name when prompted, and press **Enter**.
86
96
87
97
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
96
106
97
107
Let's make the greeting more personal by also asking for the user's favorite color and including it in the message.
98
108
99
-
1. Add two more lines below your existing code to ask fora favorite color andinclude 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:
100
110
101
111
```python
102
112
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
106
116
1. Your complete program should now look like this:
107
117
108
118
```python
119
+
# Display a welcome message
109
120
print("Welcome to the greeting program!")
121
+
122
+
# Ask for the user's name
110
123
name =input("What is your name? ")
124
+
125
+
# Display a personalized greeting
111
126
print(f"Hello, {name}! It's great to meet you.")
127
+
128
+
# Ask for the user's favorite color and extend the greeting
112
129
color =input("What is your favorite color? ")
113
130
print(f"Great choice! {color} is a wonderful color.")
114
131
```
@@ -132,7 +149,7 @@ Using an AI assistant (like Copilot) is great way to explore a programming lang
132
149
### Discovery 1: Create a decorative border
133
150
134
151
**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 print20 dashes in a row without typing them all out? Can you show me an example?```
136
153
137
154
**After the AI responds:** String repetition is a quick way to draw dividers orformat output. Try running any examples the AI gives you in the online editor, and experiment with different characters and lengths.
138
155
@@ -148,7 +165,7 @@ print("-" * 20)
148
165
### Discovery 2: Transforming text
149
166
150
167
**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?```
152
169
153
170
***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.
154
171
@@ -172,7 +189,7 @@ titlecase_name = name.title()
172
189
173
190
### Discovery 3: Printing punctuation
174
191
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?```
176
193
177
194
**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.
Copy file name to clipboardExpand all lines: Instructions/Exercises/02-calculate-students-gpa.md
+45-43Lines changed: 45 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,11 +24,31 @@ This exercise takes approximately **20** minutes.
24
24
25
25
1. Clear any default code from the editor so you're starting with a clean file.
26
26
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-isfor now. In the steps that follow, you'll add code beneath each comment.
46
+
27
47
## Store grades as variables
28
48
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 ashardcoded variables. Each score is a number out of 100.
30
50
31
-
1.In the editor pane, type the following code:
51
+
1. Beneath the `# Collect subject scores` comment, add the following lines:
32
52
33
53
```python
34
54
math_score = 88.0
@@ -39,7 +59,7 @@ You'll start by storing a student's subject scores as variables. Each score is a
39
59
40
60
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.
41
61
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:
43
63
44
64
```python
45
65
print("Scores entered:")
@@ -49,7 +69,7 @@ You'll start by storing a student's subject scores as variables. Each score is a
49
69
print(f" History: {history_score}")
50
70
```
51
71
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:
53
73
54
74
```output
55
75
Scores entered:
@@ -59,55 +79,33 @@ You'll start by storing a student's subject scores as variables. Each score is a
59
79
History: 83.5
60
80
```
61
81
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:
63
85
64
-
Now you'll use arithmetic to add up the scores and calculate the average.
86
+
$$GPA = \frac{average}{100} \times 4.0$$
65
87
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:
67
89
68
90
```python
69
91
total = math_score + english_score + science_score + history_score
70
92
num_subjects = 4
71
93
average = total / num_subjects
94
+
gpa = (average /100) *4.0
72
95
```
73
96
74
-
1. Add a print statement to display the result:
97
+
2. Beneath the `# Display the results` comment, add the following lines of code:
75
98
76
99
```python
77
-
print(f"\nTotal score: {total}")
100
+
print(f"\nTotal score: {total}")
78
101
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
-
GPAis 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")
102
104
```
103
105
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.
105
107
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:
Hardcoded values are useful for testing, but a real program should accept inputfrom 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.
129
127
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:
131
129
132
130
```python
133
131
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
142
140
1. Keep the rest of your code exactly as it is. Your complete program should now look like this:
143
141
144
142
```python
143
+
# Collect subject scores
145
144
print("Enter scores out of 100 for each subject:\n")
146
145
math_score =float(input("Math score: "))
147
146
english_score =float(input("English score: "))
148
147
science_score =float(input("Science score: "))
149
148
history_score =float(input("History score: "))
150
149
150
+
# Display the entered scores
151
151
print("\nScores entered:")
152
152
print(f" Math: {math_score}")
153
153
print(f" English: {english_score}")
154
154
print(f" Science: {science_score}")
155
155
print(f" History: {history_score}")
156
156
157
+
# Calculate the total, average, and GPA
157
158
total = math_score + english_score + science_score + history_score
158
159
num_subjects =4
159
160
average = total / num_subjects
160
161
gpa = (average /100) *4.0
161
162
163
+
# Display the results
162
164
print(f"\nTotal score: {total}")
163
165
print(f"Number of subjects: {num_subjects}")
164
166
print(f"Average score: {average}")
@@ -167,7 +169,7 @@ Hardcoded values are useful for testing, but a real program should accept input
167
169
168
170
1. Run the program. When each prompt appears in the output terminal, click on it, type a score, and press **Enter**.
169
171
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:
0 commit comments