Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import random
  2. import math
  3. import re
  4.  
  5. def getRandomNumber():
  6. random_list = []
  7. NUM_NUMBERS = 4
  8. for i in range(0,NUM_NUMBERS):
  9. random_list.append(random.randrange(1,10))
  10. print('Four given numbers:', ','.join([str(x) for x in random_list]))
  11. return random_list
  12.  
  13.  
  14.  
  15. def checkUserInput(numberList,userInput):
  16. numbers_in_user_input = re.findall('\d+',userInput)
  17. if list.sort(numbers_in_user_input) == list.sort(numberList):
  18. print('right')
  19. else:
  20. print('wrong')
  21. print(numbers_in_user_input)
  22. print(numberList)
  23.  
  24.  
  25.  
  26.  
  27. def main():
  28. number_list = getRandomNumber()
  29. user_input = input("Please enter an equation that equals 24 based on the given numbers using 'x' for multiplcation, '/' for division, '+' for addition and '-' for subtraction: ")
  30. checkUserInput(number_list,user_input)
  31.  
  32. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement