Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
947feeb
commit 5bd6d19
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Convert the following code into code that uses a for loop. | ||
|
||
# prints 2 | ||
# prints 4 | ||
# prints 6 | ||
# prints 8 | ||
# prints 10 | ||
# prints Goodbye! | ||
|
||
for i in range(2, 11, 2): | ||
print(i) | ||
print("Goodbye!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Convert the following code into code that uses a for loop. | ||
|
||
# prints Hello! | ||
# prints 10 | ||
# prints 8 | ||
# prints 6 | ||
# prints 4 | ||
# prints 2 | ||
|
||
print("Hello!") | ||
for i in range(10, 1, -2): | ||
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Write a for loop that sums the values 1 through end, inclusive. end is a variable that we define for you. | ||
# So, for example, if we define end to be 6, your code should print out the result: | ||
# 21 | ||
# which is 1 + 2 + 3 + 4 + 5 + 6. | ||
|
||
end = 6 | ||
s = 0 | ||
for num in range(0,end + 1): | ||
s = s + num | ||
print(s) |