Python Rewrite.

Hi All,

As an exercise I thought I would see if I could rewrite the code below from this tutorial http://www.sthurlow.com/python/lesson11/.


def menu(list, question):
    for entry in list:
        print 1 + list.index(entry),
        print ") " + entry

    return input(question) - 1

# running the function
# remember what the backslash does
answer = menu(['A','B','C','D','E','F','H','I'],
'Which letter is your favourite? ')

print 'You picked answer ' + (answer + 1)

and this is the result I got.


Alphlist = ['A','B','C','D','E','F','H','I']
for i in range(len(Alphlist)):
        print i+1, ")",Alphlist[i]
num= int(input('Which letter is your favourite? '))-1
print "Your Favourite letter is:", Alphlist[num]
This entry was posted in Code, Experiments. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *