/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Juego para adivinar el numero. # Fran Lucena import random intentos = 0 print "Hola! Escribe tu nombre" #El programa te pide que escribas tu nombre y lo guarda en miNombre miNombre = raw_input() secreto = random.randint(1, 20) print miNombre," , Estoy pensando un numero entre 1 y 20." while intentos < 6: print 'Adivinalo !' # Usa tabulador antes de print. #numero_jugador = int (input()) numero_jugador = raw_input() numero_jugador = int(numero_jugador) intentos = intentos + 1 # intentos += 1 if numero_jugador < secreto: print "Tu numero es menor que el secreto." # Dos veces tabulador antes de print. if numero_jugador > secreto: print "Tu numero es mayor que el secreto." if numero_jugador == secreto: break if numero_jugador == secreto: print "Correcto, ", miNombre, "! has adivinado mi numero en ", intentos , " intentos!" if numero_jugador != secreto: print "Has Perdido! El numero que yo he pensado era ", secreto
Comments
