Do not place the message correctly in python

0

I want that when the user enters one of those numbers, the corresponding message appears, but this way a "4" appears in the Run current file of sublime text 3

number = 8
guess = 4

if str(input("4")):
    print("Seleccionaste el numero menor")
elif str(input("8")):
    print("Seleccionaste el numero mayor")
    
asked by Japc 18.07.2018 в 23:39
source

1 answer

1

Assuming you have Python 3, I'll answer you first. Why does it print 4? You print the 4 by the input, the input prints in the console and receives a variable of the same. If you press enter after the 4 is shown, the 8 will be printed also by the other input of this line elif str(input("8")): and if you press enter again the program will end.

To give an answer to your problem, as you were told, you do not make any comparison:

number = 4
guess = 8
numeroIngresado=int(input("Ingresa un numero"))
if numeroIngresado==number:
   print("Seleccionaste el numero menor")
elif numeroIngresado==guess:
   print("Seleccionaste el numero mayor")

Another way to do it (not recommended):

number = '4'
guess = '8'
numeroIngresado=input("Ingresa un numero")
if numeroIngresado==number:
   print("Seleccionaste el numero menor")
elif numeroIngresado==guess:
   print("Seleccionaste el numero mayor")

The program that you seem to be trying to do, a loop can improve this program.

guess = '4'
print("Adivina el numero")
numeroIngresado=input("Ingresa un numero: ")
if numeroIngresado < guess:
    print("El numero ingresado es menor")
elif numeroIngresado > guess:
    print("El numero ingresado es mayor")
elif numeroIngresado==guess:
    print("Adivinaste el numero")
    
answered by 19.07.2018 в 06:48