SHOW:
|
|
- or go back to the newest paste.
| 1 | import random | |
| 2 | ||
| 3 | def choose_difficulty(): | |
| 4 | print("🎮 Wybierz poziom trudności:")
| |
| 5 | print("1 - Łatwy (1–10)")
| |
| 6 | print("2 - Normalny (1–50)")
| |
| 7 | print("3 - Trudny (1–100)")
| |
| 8 | while True: | |
| 9 | choice = input("Twój wybór (1/2/3): ")
| |
| 10 | if choice == '1': | |
| 11 | return 1, 10 | |
| 12 | elif choice == '2': | |
| 13 | return 1, 50 | |
| 14 | elif choice == '3': | |
| 15 | return 1, 100 | |
| 16 | else: | |
| 17 | print("Niepoprawny wybór. Spróbuj ponownie.")
| |
| 18 | ||
| 19 | def is_valid_integer(text): | |
| 20 | return text.isdigit() | |
| 21 | ||
| 22 | def play_game(): | |
| 23 | low, high = choose_difficulty() | |
| 24 | secret = random.randint(low, high) | |
| 25 | attempts = 0 | |
| 26 | previous_diff = None | |
| 27 | ||
| 28 | print(f"\n🔢 Zgadnij liczbę od {low} do {high}!")
| |
| 29 | ||
| 30 | while True: | |
| 31 | user_input = input("Twoja liczba: ")
| |
| 32 | if not is_valid_integer(user_input): | |
| 33 | print("⚠️ Podaj poprawną liczbę całkowitą!")
| |
| 34 | continue | |
| 35 | ||
| 36 | guess = int(user_input) | |
| 37 | if guess < low or guess > high: | |
| 38 | print(f"🚫 Liczba poza zakresem! Podaj liczbę od {low} do {high}.")
| |
| 39 | continue | |
| 40 | ||
| 41 | attempts += 1 | |
| 42 | current_diff = abs(secret - guess) | |
| 43 | ||
| 44 | if guess == secret: | |
| 45 | print(f"🎉 Brawo! Trafiłeś w {attempts} próbach.")
| |
| 46 | return attempts | |
| 47 | ||
| 48 | if previous_diff is None: | |
| 49 | if current_diff > (high - low) // 2: | |
| 50 | print("🥶 Zimno...")
| |
| 51 | else: | |
| 52 | print("🌡️ Ciepło!")
| |
| 53 | else: | |
| 54 | if current_diff < previous_diff: | |
| 55 | print("🔥 Goręcej!")
| |
| 56 | elif current_diff > previous_diff: | |
| 57 | print("❄️ Zimniej!")
| |
| 58 | else: | |
| 59 | print("😐 Tak samo jak poprzednio...")
| |
| 60 | ||
| 61 | previous_diff = current_diff | |
| 62 | ||
| 63 | def main(): | |
| 64 | results = [] | |
| 65 | ||
| 66 | print("🎯 Witaj w grze: Ciepło–Zimno – Zgadnij Liczbę!")
| |
| 67 | ||
| 68 | while True: | |
| 69 | attempts = play_game() | |
| 70 | results.append(attempts) | |
| 71 | ||
| 72 | again = input("\nCzy chcesz zagrać jeszcze raz? (t/n): ").lower()
| |
| 73 | if again != 't': | |
| 74 | break | |
| 75 | ||
| 76 | print("\n📊 Twoje wyniki:")
| |
| 77 | for i, tries in enumerate(results, 1): | |
| 78 | print(f"Runda {i}: {tries} prób")
| |
| 79 | print(f"🔚 Średnia liczba prób: {sum(results) / len(results):.2f}")
| |
| 80 | ||
| 81 | if __name__ == "__main__": | |
| 82 | main() |