Created
March 1, 2021 01:54
-
-
Save jdevries3133/60d55ae9bb523da34813089bab12b5ed to your computer and use it in GitHub Desktop.
Help for /u/Ok-Design-3218 (reddit)
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
mystery_int_1 = 3 | |
mystery_int_2 = 4 | |
mystery_int_3 = 5 | |
#You may modify the lines of code above, but don't move them! | |
#When you Submit your code, we'll change these lines to | |
#assign different values to the variables. | |
#Above are three values. Run a while loop until all three | |
#values are less than or equal to 0. Every time you change | |
#the value of the three variables, print out their new values | |
#all on the same line, separated by single spaces. For | |
#example, if their values were 3, 4, and 5 respectively, your | |
#code would print: | |
# | |
#2 3 4 | |
#1 2 3 | |
#0 1 2 | |
#-1 0 1 <=======(current code stops running here) | |
#-2 -1 0 | |
#### solution 1 #### | |
while max(mystery_int_1, mystery_int_2, mystery_int_3) > 0: | |
mystery_int_1 -= 1 | |
mystery_int_2 -= 1 | |
mystery_int_3 -= 1 | |
print(mystery_int_1,mystery_int_2,mystery_int_3) | |
#### solution 2 #### | |
mystery_int_1 = 3 | |
mystery_int_2 = 4 | |
mystery_int_3 = 5 | |
for _ in range(max(mystery_int_1, mystery_int_2, mystery_int_3)): | |
mystery_int_1 -= 1 | |
mystery_int_2 -= 1 | |
mystery_int_3 -= 1 | |
print( | |
mystery_int_1, | |
mystery_int_2, | |
mystery_int_3 | |
) | |
#### solution 3 #### | |
# same as #2 put it puts the values in a list. Notice how much | |
# less code there is overal! | |
vals = [3, 4, 5] | |
for _ in range(max(vals)): | |
vals = [v - 1 for v in vals] | |
print(vals) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment