Problemas de bucle a un punto en la entrada de código de validación

0

Pregunta

No he sido capaz de averiguar cómo bucle mi código de nuevo a un punto específico, tengo 2 puntos de bucle y el primero funciona bien pero no puedo conseguir el segundo, para trabajar como tengo que definir la variable de entero "num_stores_int" pero si lo hago, entonces el bucle "while" no funciona. Ver mi código para donde los puntos son.

Aquí está mi código:

num_stores = ("")
num_stores_int = int(num_stores)
while num_stores.isnumeric() == False:
    while num_stores_int > 10: #This is where I want it to loop to 
        num_stores = input ("\n To start, please enter the amount of stores you own: ")
        if num_stores.isnumeric() == True:
            num_stores_int = int(num_stores)
            if num_stores_int > 10: #this is where I want the "while" loop to validate the integer being less than 10
                print (" Sorry, this sales tracker can track a maximum of 10 stores.\n Here, try that again, I'll reboot it for you.\n")
                print (" -----------------------REBOOTING------------------------")
            if num_stores_int >= 5:
                print ("\n Hmm, interesting, you'd think someone with that many \n stores would be able to afford a better sales tracker.")
                print (" Well, I guess you're stuck with me! MUHAHAHAHA!!......\n\n Anyway,")
                print (f" clearly big business person, you own {num_stores_int} stores.\n I'm gonna need you to tell me where each one is")
            else:
                num_stores_int = int(num_stores)
                print (f" Alright... so, random business person, you have {num_stores_int} stores.\n Now, I'm going to need you to tell me where each one is")
        else:
            print ("\n Hey, uhh, you're going to have to write a number for the\n amount of stores you've got, letters and decimals don't \n really work. Here, try again, I'll reboot it for you.\n")
            print (" -----------------------REBOOTING------------------------")
integer loops python validation
2021-11-23 02:30:07
2
0

No es súper claro lo que están buscando, pero creo que tu exterior while bucle está destinado a evitar preguntar al usuario para la entrada cuando la entrada de algo que no es numérica?

Yo sólo la envoltura que while bucle de todo el código que solicita la entrada del usuario, de la siguiente manera:

num_stores = ("")
num_stores_int = 0
while num_stores_int < 10: #This is where I want it to loop to
    num_stores = input ("\n To start, please enter the amount of stores you own:")
    while num_stores.isnumeric() == False:
        print ("\n Hey, uhh, you're going to have to write a number for the\n amount of stores you've got, letters and decimals don't \n really work. Here, try again, I'll reboot it for you.\n")
        print (" -----------------------REBOOTING------------------------")
        num_stores = input ("\n To start, please enter the amount of stores you own:")

    num_stores_int = int(num_stores)
    if num_stores_int > 10: #this is where I want the "while" loop to validate the integer being less than 10
        print (" Sorry, this sales tracker can track a maximum of 10 stores.\n Here, try that again, I'll reboot it for you.\n")
        print (" -----------------------REBOOTING------------------------")
    elif num_stores_int >= 5:
        print ("\n Hmm, interesting, you'd think someone with that many \n stores would be able to afford a better sales tracker.")
        print (" Well, I guess you're stuck with me! MUHAHAHAHA!!......\n\n Anyway,")
        print (f" clearly big business person, you own {num_stores_int} stores.\n I'm gonna need you to tell me where each one is")
    else:
        print (f" Alright... so, random business person, you have {num_stores_int} stores.\n Now, I'm going to need you to tell me where each one is")
2021-11-23 02:51:38

Sí, el exterior del bucle while es trabajo para mí, pero el interior no se porque tengo que definir la variable de entero num_stores_int con el fin de comprobar si está en el número 10, pero si lo hago, voy a tomar la ya definida valor y no el de las entradas de usuario y así no funciona
Weaver Ant

@Clandestinidad podrías ser más específico acerca de lo que no funciona con el código que he publicado
Erik McKelvey

oh disparar yo no noto el cambio y el pensamiento que acaba de reposteado mi mismo código. Wow, no me esperaba que trabajar. Muchas gracias hombre!!
Weaver Ant

@Clandestinidad veo que eres nuevo en ESO. Si usted siente una respuesta resuelto el problema, por favor marque como "aceptado" haciendo clic en la marca de verificación verde. Esto ayuda a mantener el foco en las personas de edad, ASÍ que todavía no tengo respuestas.
Erik McKelvey

Uff que obvio xD, gracias, Gracias, estaba buscando algo para marcarlo como la respuesta correcta. Lo siento, es tarde y mi cerebro es totalmente frito XD
Weaver Ant

@Clandestinidad Todo bien, gracias!
Erik McKelvey

yo lo siento por la cancelación de la cosa de la que me di cuenta que no soluciona el problema. Es mi mal, me expliqué mal, pero acabo de intentar algo y funcionó. Gracias por la ayuda de todos modos!
Weaver Ant

Mejor respuesta

0

Mi mal, debe de haber mal explicado lo que estaba mal, pero acabo de intentar algo y funcionó.

def restart():
    num_stores = ("")
    while num_stores.isnumeric() == False: 
        num_stores = input ("\n To start, please enter the amount of stores you own: ")
        if num_stores.isnumeric() == True:
            num_stores_int = int(num_stores)
            if num_stores_int > 10:
                print ("\n Sorry, this sales tracker can track a maximum of 10 stores.\n Here, try that again, I'll reboot it for you.\n")
                print (" -----------------------REBOOTING------------------------")
                restart()
            elif num_stores_int >= 5:
                print ("\n Hmm, interesting, you'd think someone with that many \n stores would be able to afford a better sales tracker.")
                print (" Well, I guess you're stuck with me! MUHAHAHAHA!!......\n\n Anyway,")
                print (f" clearly big business person, you own {num_stores_int} stores. I'm gonna\n need you to tell me where each one is")
            else:
                num_stores_int = int(num_stores)
                print (f" Alright... so, random business person, you have {num_stores_int} stores.\n Now, I'm going to need you to tell me where each one is")
        else:
            print ("\n Hey, uhh, you're going to have to write a number for the\n amount of stores you've got, letters and decimals don't \n really work. Here, try again, I'll reboot it for you.\n")
            print (" -----------------------REBOOTING------------------------")
restart()
2021-11-23 02:41:49

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................