tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View 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)