Problemi di loop di un punto in input il codice di convalida

0

Domanda

Io non sono stato in grado di capire come loop il mio codice di un punto specifico, ho 2 punti di loop e il primo funziona bene, ma non può ottenere la seconda a lavorare come devo definire la variabile integer "num_stores_int" ma se le faccio, quindi il "mentre" il ciclo non funziona. Vedere il mio codice per cui i punti sono.

Ecco il mio codice:

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

Non è super chiaro che cosa si sta cercando, ma credo che il tuo esterno while loop è destinata a continuare a chiedere all'utente per l'input quando possono inserire qualcosa che non è numerico?

Vorrei solo involucro che while giro ad anello del codice che richiede l'input dell'utente, come 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

Sì, l'esterno mentre il ciclo è lavoro per me, ma l'interno non è perché devo definire la variabile integer num_stores_int per verificare se è sotto il numero 10, ma se lo faccio, lo prenderò già definiti e non quello che l'utente ingressi e quindi non funziona
Weaver Ant

@Clandestinità potresti essere più specifico su ciò che non funziona con il codice che ho postato
Erik McKelvey

oooh sparare non ho notato il cambiamento e il pensiero che hai appena ripostato il mio stesso codice. Wow, non mi aspettavo che per lavoro. Grazie mille uomo!!
Weaver Ant

@Clandestinità vedo che sei nuovo QUINDI. Se si sente una risposta risolto il problema, si prega di contrassegnare come "accettato" facendo clic sul segno di spunta verde. Questo aiuta a mantenere il focus sui vecchi in MODO che ancora non hanno risposte.
Erik McKelvey

Yikes che ovvio xD, Grazie stavo cercando qualcosa di indicare che è la risposta giusta. Mi dispiace, è tardi e il mio cervello è totalmente fritto XD
Weaver Ant

@Clandestinità Tutto bene, grazie!
Erik McKelvey

yo mi dispiace per la cancellazione la cosa che ho appena realizzato di non risolvere il problema. È il mio male, mi sono spiegato male, ma ho appena provato qualcosa e ha funzionato. Grazie per l'aiuto comunque!
Weaver Ant

Migliore risposta

0

Il mio male, devo aver mal spiegato che cosa era sbagliato, ma ho appena provato qualcosa e ha funzionato.

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

In altre lingue

Questa pagina è in altre lingue

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