SHARE
TWEET

Eurojackpot2

DeaD_EyE Jul 7th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # origin: https://pastebin.com/mpCn2UJ6
  2.  
  3.  
  4. from itertools import count
  5. import random
  6.  
  7.  
  8. def input_number(min_val, max_val):
  9.     while True:
  10.         user_input = input(f"Gebe eine ganze Zahl zwischen {min_val} und {max_val} ein: ")
  11.         try:
  12.             number = int(user_input)
  13.         except ValueError:
  14.             print(user_input, 'ist keine Ganzzahl')
  15.             continue
  16.         if not min_val <= number <= max_val:
  17.             print('Die zahl {number} ist zu groƟ oder zu klein')
  18.             continue
  19.         return number
  20.  
  21.  
  22. def guess_repeat(min_val, max_val, repeats):
  23.     eingabe = []
  24.     for i in range(repeats):
  25.         number = input_number(min_val, max_val)
  26.         eingabe.append(number)
  27.     eingabe.sort()
  28.     return eingabe
  29.  
  30.  
  31. def get_random_sample(min_val, max_val, repeats):
  32.     population = range(min_val, max_val + 1)
  33.     sample = random.sample(population, repeats)
  34.     sample.sort()
  35.     return sample
  36.    
  37.  
  38. def game_logic():
  39.     eingabe = guess_repeat(1, 10, 5) + guess_repeat(1, 3, 2)
  40.     for ziehung in count(1):
  41.         sample = get_random_sample(1, 10, 5) + get_random_sample(1, 3, 2)
  42.         if sample == eingabe:
  43.             print(f"Du hast den Jackpot geknackt. {ziehung} Ziehungen.")
  44.             print(sample)
  45.             return
  46.  
  47.  
  48. if __name__ == '__main__':
  49.     game_logic()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top