Problem z przejściem do punktu w kodzie sprawdzania poprawności danych wejściowych

0

Pytanie

Nie mogłem zrozumieć, jak powtarzać swój kod do pewnego punktu, mam 2 punkty cyklu, i pierwsza działa normalnie, ale nie mogę zmusić do pracy drugą, tak, jak muszę określić целочисленную zmienną "num_stores_int", ale jeśli to zrobię, to pętla "while" nie działa. Zobacz mój kod, gdzie znajdują się te punkty.

Oto mój kod:

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

Nie jest do końca jasne, co szukasz, ale uważam, że twój zewnętrzny while cykl jest przeznaczony do tego, aby kontynuować monitował użytkownika o podanie, kiedy wprowadza coś nie numeryczne?

Ja bym tylko zawinął to while wykonaj pętlę wokół kodu, wnioskując wprowadzanie danych przez użytkownika, w następujący sposób:

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

Tak, zewnętrzna pętla while działa dla mnie, ale wewnętrzny-nie, bo muszę ustalić целочисленную zmienną num_stores_int, aby sprawdzić, czy znajduje się ona pod numerem 10, ale jeśli to zrobię, ona weźmie już pewną wartość, a nie to, które wprowadza użytkownik, i dlatego nie działa
Weaver Ant

@Clandestinity Nie mógłbyś sprecyzować, że nie działa z kodem, który opublikowałem
Erik McKelvey

oooo, nie zauważyłem zmian i myślę, że ty po prostu перепостил mój jest ten sam kod. Wow, nie spodziewałem się, że to zadziała. Bardzo ci dziękuję, facet!!
Weaver Ant

@Podziemia, widzę, że jesteś nowy w tym. Jeśli uważasz, że odpowiedź rozwiązałem problem, proszę zaznaczyć go jako "przyjęte", klikając zielony znacznik wyboru. To pomaga skupić się na starych tematach, na które wciąż nie ma odpowiedzi.
Erik McKelvey

Dużo tego oczywistego xD Dziękuję, że szukałem czegoś, aby zauważyć to jak poprawna odpowiedź. Przepraszam, już późno i mój mózg całkowicie spalony XD
Weaver Ant

@Clandestinity Wszystko w porządku, dziękuję!
Erik McKelvey

hej, przepraszam, że zniósł to, czego zdałem sobie sprawę, że to nie rozwiązuje problemu. To moja wina, źle wyjaśnił, ale ja po prostu starałem się coś, i to się udało. W każdym razie, dziękuję za pomoc!
Weaver Ant

Najlepsza odpowiedź

0

Moja wina, nie musi być źle wyjaśnił, co było nie tak, ale ja po prostu starałem się coś, i to się udało.

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

W innych językach

Ta strona jest w innych językach

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