basics_iii
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| basics_iii [2023/10/13 06:13] – appledog | basics_iii [2023/10/13 11:48] (current) – appledog | ||
|---|---|---|---|
| Line 58: | Line 58: | ||
| For homework ask them to include a round counter, which keeps track of how many guesses they make. | For homework ask them to include a round counter, which keeps track of how many guesses they make. | ||
| + | == Advanced | ||
| + | Here is a " | ||
| + | |||
| + | < | ||
| + | import random | ||
| + | |||
| + | list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
| + | random.shuffle(list) | ||
| + | |||
| + | score = 0 | ||
| + | |||
| + | while list != sorted(list): | ||
| + | score = score + 1 | ||
| + | print(list) | ||
| + | print(" | ||
| + | |||
| + | x = input(" | ||
| + | y = input(" | ||
| + | |||
| + | try: | ||
| + | x = int(x) - 1 | ||
| + | y = int(y) - 1 | ||
| + | except: | ||
| + | print("" | ||
| + | print(" | ||
| + | score = score - 1 | ||
| + | continue | ||
| + | |||
| + | (list[x], list[y]) = (list[y], list[x]) | ||
| + | |||
| + | print (" | ||
| + | |||
| + | print(list) | ||
| + | print(" | ||
| + | print(" | ||
| + | |||
| + | </ | ||
basics_iii.1697177628.txt.gz · Last modified: 2023/10/13 06:13 by appledog
