Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def choose_difficulty():
- print("🎮 Wybierz poziom trudności:")
- print("1 - Łatwy (1–10)")
- print("2 - Normalny (1–50)")
- print("3 - Trudny (1–100)")
- while True:
- choice = input("Twój wybór (1/2/3): ")
- if choice == '1':
- return 1, 10
- elif choice == '2':
- return 1, 50
- elif choice == '3':
- return 1, 100
- else:
- print("Niepoprawny wybór. Spróbuj ponownie.")
- def is_valid_integer(text):
- return text.isdigit()
- def play_game():
- low, high = choose_difficulty()
- secret = random.randint(low, high)
- attempts = 0
- previous_diff = None
- print(f"\n🔢 Zgadnij liczbę od {low} do {high}!")
- while True:
- user_input = input("Twoja liczba: ")
- if not is_valid_integer(user_input):
- print("⚠️ Podaj poprawną liczbę całkowitą!")
- continue
- guess = int(user_input)
- if guess < low or guess > high:
- print(f"🚫 Liczba poza zakresem! Podaj liczbę od {low} do {high}.")
- continue
- attempts += 1
- current_diff = abs(secret - guess)
- if guess == secret:
- print(f"🎉 Brawo! Trafiłeś w {attempts} próbach.")
- return attempts
- if previous_diff is None:
- if current_diff > (high - low) // 2:
- print("🥶 Zimno...")
- else:
- print("🌡️ Ciepło!")
- else:
- if current_diff < previous_diff:
- print("🔥 Goręcej!")
- elif current_diff > previous_diff:
- print("❄️ Zimniej!")
- else:
- print("😐 Tak samo jak poprzednio...")
- previous_diff = current_diff
- def main():
- results = []
- print("🎯 Witaj w grze: Ciepło–Zimno – Zgadnij Liczbę!")
- while True:
- attempts = play_game()
- results.append(attempts)
- again = input("\nCzy chcesz zagrać jeszcze raz? (t/n): ").lower()
- if again != 't':
- break
- print("\n📊 Twoje wyniki:")
- for i, tries in enumerate(results, 1):
- print(f"Runda {i}: {tries} prób")
- print(f"🔚 Średnia liczba prób: {sum(results) / len(results):.2f}")
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment