Problemas de loop para um ponto de entrada de código de validação

0

Pergunta

Eu não tenho sido capaz de descobrir como loop meu código para um ponto específico, eu tenho 2 pontos de loop e o primeiro funciona bem, mas eu não posso fazer o segundo, um para o trabalho, como eu tenho que definir a variável de número inteiro "num_stores_int" mas se eu fizer, então o loop "while" não funciona. Veja o meu código para onde esses pontos são.

Aqui está o meu 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

Ele não é super claro o que você está procurando, mas eu acredito que o seu exterior while ciclo destina-se a manter a pedir a entrada do usuário quando eles de entrada em algo que não é numérico?

Gostaria apenas o envoltório que while loop em torno do código que faz para a entrada do usuário, como segue:

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

Sim, o loop mais externo é trabalho para mim, mas o interior não é porque eu tenho que definir a variável de número inteiro num_stores_int, a fim de verificar se é sob o número 10, mas se eu fizer, vai tomar o já definido o valor e não o que as entradas de usuário e por isso não funciona
Weaver Ant

@Clandestinidade, você Poderia ser mais específico sobre o que não funciona com o código que eu postei
Erik McKelvey

oooh atirar eu não notar a mudança e pensei que você apenas repostado meu mesmo código. Wow, eu não esperava que trabalhar. Muito obrigado man!!
Weaver Ant

@Clandestinidade, vejo que você é novo para ISSO. Se você sentir que uma resposta resolvido o problema, por favor, marque-a como 'aceito' clicando na marca de verificação verde. Isso ajuda a manter o foco nos mais velhos, de MODO que ainda não têm respostas.
Erik McKelvey

Caramba que óbvio xD, Obrigado eu estava procurando algo para marcá-lo como o direito de resposta. Sinto muito, é tarde e meu cérebro está totalmente frito XD
Weaver Ant

@Clandestinidade, Tudo de bom, obrigado!
Erik McKelvey

yo pena de anulação de coisa que eu só percebi isso não corrigir o problema. É o meu mal, eu expliquei mal, mas eu só tentei algo e funcionou. Obrigado pela ajuda de qualquer maneira!
Weaver Ant

Melhor resposta

0

My bad, eu devia mal explicou o que estava errado, mas eu apenas tentei algo e funcionou.

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

Em outros idiomas

Esta página está em outros idiomas

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