Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # origin: https://pastebin.com/mpCn2UJ6
- from itertools import count
- import random
- def input_number(min_val, max_val):
- while True:
- user_input = input(f"Gebe eine ganze Zahl zwischen {min_val} und {max_val} ein: ")
- try:
- number = int(user_input)
- except ValueError:
- print(user_input, 'ist keine Ganzzahl')
- continue
- if not min_val <= number <= max_val:
- print('Die zahl {number} ist zu groΓ oder zu klein')
- continue
- return number
- def guess_repeat(min_val, max_val, repeats):
- eingabe = []
- for i in range(repeats):
- number = input_number(min_val, max_val)
- eingabe.append(number)
- eingabe.sort()
- return eingabe
- def get_random_sample(min_val, max_val, repeats):
- population = range(min_val, max_val + 1)
- sample = random.sample(population, repeats)
- sample.sort()
- return sample
- def game_logic():
- eingabe = guess_repeat(1, 10, 5) + guess_repeat(1, 3, 2)
- for ziehung in count(1):
- sample = get_random_sample(1, 10, 5) + get_random_sample(1, 3, 2)
- if sample == eingabe:
- print(f"Du hast den Jackpot geknackt. {ziehung} Ziehungen.")
- print(sample)
- return
- if __name__ == '__main__':
- game_logic()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement