Problémy looping do bodu vstupu overovací kód

0

Otázka

Nebol som schopný zistiť, ako slučky môj kód späť na konkrétny bod, mám 2 slučky body a prvý funguje, ale nemôžem si druhú prácu ako som sa definovať hodnotu premennej "num_stores_int" ale ak ja, potom ", zatiaľ čo" slučky nefunguje. Pozrite si časť moja kód, kde sa tieto body sú.

Tu 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

To nie je super jasné, čo hľadáte, ale verím, že vaše vonkajšie while slučky je určený, aby požiadala používateľa pre vstup keď majú vstup niečo, čo nie je číselný?

Ja by som len zábal, že while slučka okolo kód, ktorý požiada o vstup používateľa, a to takto:

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, vonkajší počas slučky je práca pre mňa, ale vnútorný nie je preto, že som na definovanie celočíselnú premennú num_stores_int s cieľom skontrolovať, či nie je pod číslom 10 ale keď robím, to budem mať už definované hodnoty a nie jeden užívateľ vstupy a tak nefunguje
Weaver Ant

@Clandestinity Mohli by ste byť konkrétnejší, o tom, čo nefunguje s kódu som sa pridal
Erik McKelvey

oooh strieľať som si nevšimol zmenu, a myslel, že si len prevzaté moje rovnaký kód. Wow, nečakal som, že do práce. Ďakujem moc človeka!!
Weaver Ant

@Clandestinity vidím, že ste TAK urobili. Ak máte pocit, odpoveď vyriešil problém, označte ho ako 'prijaté' kliknutím na zelenú značku. To pomáha udržať zameranie na starších TAKŽE, ktoré ešte nemáte odpovede.
Erik McKelvey

Yikes, že zrejmé, xD, Ďakujem, hľadala som niečo, čo ho označiť ako správnu odpoveď. Je mi ľúto, že je neskoro a môj mozog je úplne vyprážané XD
Weaver Ant

@Clandestinity Všetko dobré, ďakujem!
Erik McKelvey

jo sorry za zrušenie vec, len som si to problém nevyriešila. Je to moje zlé, vysvetlil som to zle, ale len som sa snažil niečo a fungovalo to. Ďakujem za pomoc rovnako!
Weaver Ant

Najlepšiu odpoveď

0

Moje zlé, musím si zle vysvetlil, čo bolo zle, ale len som sa snažil niečo 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 iných jazykoch

Táto stránka je v iných jazykoch

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