tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
22
Task/Number-reversal-game/Python/number-reversal-game.py
Normal file
22
Task/Number-reversal-game/Python/number-reversal-game.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
'''
|
||||
number reversal game
|
||||
Given a jumbled list of the numbers 1 to 9
|
||||
Show the list.
|
||||
Ask the player how many digits from the left to reverse.
|
||||
Reverse those digits then ask again.
|
||||
until all the digits end up in ascending order.
|
||||
|
||||
'''
|
||||
|
||||
import random
|
||||
|
||||
print(__doc__)
|
||||
data, trials = list('123456789'), 0
|
||||
while data == sorted(data):
|
||||
random.shuffle(data)
|
||||
while data != sorted(data):
|
||||
trials += 1
|
||||
flip = int(input('#%2i: LIST: %r Flip how many?: ' % (trials, ' '.join(data))))
|
||||
data[:flip] = reversed(data[:flip])
|
||||
|
||||
print('\nYou took %2i attempts to put the digits in order!' % trials)
|
||||
Loading…
Add table
Add a link
Reference in a new issue