Piedra, Papel o Tijera en Python 2025

Descubre Piedra, Papel o Tijera en Python 2025: un juego interactivo con condicionales, bucles y manejo de errores, con ideas para IA y servicios de Q2BSTUDIO

14 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Piedra Papel o Tijera en Python 2025

En este artículo explicamos cómo crear un juego Piedra Papel o Tijera en Python y aprovechamos para repasar conceptos esenciales como condicionales, bucles y manejo de errores. También hablaremos brevemente de cómo proyectos simples como este pueden integrar inteligencia artificial y servicios profesionales que ofrece Q2BSTUDIO, especialistas en aplicaciones a medida y software a medida.

Código completo

import random

def game():

    game_options = ["Rock", "Paper", "Scissors"]

    while True:

        print()

        print("1. Rock")

        print("2. Paper")

        print("3. Scissors")

        print("4. Exit")

        try:

            user_option = int(input("Choose any one number to start the game 1-4: "))

        except ValueError:

            print("Please enter a valid number")

            continue

        if user_option == 4:

            print("Thanks for playing!")

            break

        if user_option not in [1, 2, 3]:

            print("Invalid choice Please select 1 2 3 or 4")

            continue

        user_choice = game_options[user_option - 1]

        computer_choice = random.choice(game_options)

        print(f"User {user_choice}")

        print(f"Computer {computer_choice}")

        if user_choice == computer_choice:

            print("Game Tie Play Again")

            continue

        if (user_choice == "Rock" and computer_choice == "Scissors") or (user_choice == "Paper" and computer_choice == "Rock") or (user_choice == "Scissors" and computer_choice == "Paper"):

            print(f"{user_choice} beats {computer_choice} | Winner USER")

        else:

            print(f"{computer_choice} beats {user_choice} | Winner COMPUTER")

game()

Salida de ejemplo

1. Rock 2. Paper 3. Scissors 4. Exit Choose any one number to start the game 1-4: 1 User Rock Computer Scissors Rock beats Scissors | Winner USER

Explicación paso a paso

Paso 1 Funcion principal

Todo el juego está contenido en la función game para poder ejecutarlo repetidas veces sin repetir código.

Paso 2 Opciones del juego

game_options almacena las tres opciones del juego y se usa para mapear la elección del usuario y la del ordenador.

Paso 3 Bucle infinito hasta salir

while True mantiene el juego en ejecución hasta que el usuario elige salir.

Paso 4 Menú

Se muestran cuatro opciones numeradas para que el usuario seleccione fácilmente.

Paso 5 Lectura de la opción del usuario

input permite leer la elección y se convierte a entero con int. Se captura ValueError para manejar entradas no numéricas.

Paso 6 Comprobar salida

Si el usuario introduce 4 se muestra un mensaje de agradecimiento y se sale con break.

Paso 7 Validar entrada

Si el número elegido no está en 1 2 o 3 se informa y se vuelve a pedir la entrada con continue.

Paso 8 Elecciones de usuario y ordenador

La elección del usuario se obtiene desde la lista restando 1 al número elegido. El ordenador elige aleatoriamente con random.choice entre las opciones disponibles.

Paso 9 Mostrar elecciones

Se imprime lo que han escogido usuario y ordenador.

Paso 10 Empate

Si las elecciones coinciden hay empate y se pide jugar de nuevo.

Paso 11 Determinar ganador

Se aplican las reglas básicas Rock vence a Scissors Paper vence a Rock Scissors vence a Paper y se notifica el ganador según corresponda.

Paso 12 Repetición

Tras cada ronda el bucle vuelve a mostrar el menú a menos que el usuario decida salir.

Aplicaciones y servicios profesionales con Q2BSTUDIO

En Q2BSTUDIO desarrollamos aplicaciones a medida y software a medida adaptado a las necesidades de cada cliente. Si quieres transformar este tipo de proyecto en una aplicación multiplataforma avanzada consulta nuestros servicios de desarrollo en desarrollo de aplicaciones y software multiplataforma. Además integramos soluciones de inteligencia artificial para mejorar experiencias y automatizar decisiones; si te interesa la implementación de ia para empresas o agentes IA visita nuestra página de inteligencia artificial.

Tambien ofrecemos ciberseguridad y pentesting, servicios cloud aws y azure, servicios inteligencia de negocio y consultoría en Power BI para extraer valor de los datos. Palabras clave relevantes en nuestros proyectos incluyen aplicaciones a medida software a medida inteligencia artificial ciberseguridad servicios cloud aws y azure servicios inteligencia de negocio ia para empresas agentes IA y power bi.

Conclusión

Piedra Papel o Tijera es un excelente ejercicio para aprender Python y principios de programación. Si quieres convertir una demostración en una aplicación real con integración cloud y seguridad profesional nuestro equipo en Q2BSTUDIO puede ayudarte a llevarla a producción.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat