Advertisement
skotoseme

hex quiz

May 15th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. ##
  2. # Train your hex. Note the adjustable range and step.
  3.  
  4. def hexquiz(therange=(0x0,0x100),step=0x20, cheatsheet=0x0):
  5.     """ cheatsheet=0x1 to view answers before taking quiz """
  6.     from random import randrange
  7.     pile = [i for i in range(therange[0x0],therange[0x1],step)]
  8.  
  9.     if cheatsheet == 0x1:
  10.         hexcheatsheet(therange,step)
  11.  
  12.     while len(pile) > 0x0:
  13.         answer = pile[randrange(len(pile))]
  14.         print hex(answer)
  15.         guess = int(raw_input(''))
  16.  
  17.         if guess == answer:     # if answer is correct,
  18.             print 'CORRECT'     # remove card from pile
  19.             pile.remove(answer)
  20.  
  21.         elif guess != answer:   # if answer is incorrect,
  22.             print 'INCORRECT'   # do not remove from pile and
  23.             pile.append(answer) # add an extra copy
  24.  
  25. def hexcheatsheet(therange=(0x0,0x100),step=0x10):
  26.     print 'CHEATSHEET:'
  27.     for i in range(therange[0x0],therange[0x1],step):
  28.         print hex(i), '-', i
  29.     print ''
  30.  
  31. hexquiz(cheatsheet=0x1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement