Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 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