Problémy looping k bodu v zadání ověřovací kód

0

Otázka

Nebyl jsem schopen přijít na to, jak smyčky můj kód, vrátit se do určitého bodu, mám 2 body smyčky a první z nich funguje v pořádku, ale nemůžu se dostat druhého do práce, jak mám definovat celočíselné proměnné "num_stores_int" ale když to udělám, pak "while" cyklus nebude fungovat. Viz můj kód, kde tyto body jsou.

Tady je můj kód:

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

Není to velmi jasné, co jste hledali, ale domnívám se, že vaše vnější while smyčka je určena udržet dotazem uživatele pro vstup, když vstup něco, co není číslo?

Já bych jen obal, který while smyčka kolem kódu, který žádá o vstup uživatele, a to následovně:

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

Jo, vnější while pracuje pro mě, ale ten vnitřní není, protože mám definovat celočíselné proměnné num_stores_int s cílem zkontrolovat, jestli je to pod číslem 10, ale když to udělám, to budu mít již definovanou hodnotu, a ne jeden uživatel vstupy a tak nefunguje
Weaver Ant

@Blatníky Mohl byste být konkrétnější v tom, co nefunguje s kódem jsem vyslán
Erik McKelvey

oooh střílet já jsem si té změny nevšimla a myslela, že se jen přeposlal můj stejný kód. Wow, nečekal jsem, že se do práce. Díky moc chlape!!
Weaver Ant

@Blatníky vidím, že jsi nová. Pokud máte pocit, odpověď vyřešen problém, prosím, označte jej jako "přijata", kliknutím na zelené zaškrtnutí. To pomáhá udržet zaměření na starší, TAK který stále nemáme odpovědi.
Erik McKelvey

Jejda to jasné xD Děkuji, hledal jsem něco označit jako správnou odpověď. Omlouvám se, je pozdě a můj mozek je totálně v háji XD
Weaver Ant

@Blatníky Všechno dobré, děkuji!
Erik McKelvey

jo omlouvám se za zrušení věc, jen jsem si uvědomil, že se problém nevyřeší. Je to moje chyba, že jsem to vysvětlil špatně, ale jen jsem zkoušel něco a fungovalo to. Děkuji za pomoc, stejně!
Weaver Ant

Nejlepší odpověď

0

Moje chyba, asi jsem špatně vysvětlil, co bylo špatně, ale jen jsem zkoušel něco a fungovalo to.

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

V jiných jazycích

Tato stránka je v jiných jazycích

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