Podries escriure un joc de pedra, paper, tisores en Python?
- User
Podries escriure un joc de pedra, paper, tisores en Python?
- Assistant
Sí, aquí tens un exemple senzill de com podríem escriure un joc de pedra, paper, tisores en Python:
import random
def main(): choices = ['pedra', 'paper', 'tisores'] print("Benvingut al joc de pedra, paper, tisores!") while True: player_choice = input("Escull (pedra, paper, tisores): ") if player_choice not in choices: print("Opció no vàlida. Torna-ho a provar.") continue computer_choice = random.choice(choices) print(f"Has escollit {player_choice}. El teu oponent ha escollit {computer_choice}.") if player_choice == computer_choice: print("Empat!") elif player_choice == 'pedra' and computer_choice == 'tisores' or player_choice == 'paper' and computer_choice == 'pedra' or player_choice == 'tisores' and computer_choice == 'paper': print("Has guanyat!") else: print("Has perdut.") play_again = input("Vols jugar de nou? (sí/no): ") if play_again.lower() != 'sí': break
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.