Probleme looping la un punct de intrare cod de validare

0

Problema

Nu am fost în stare să-mi dau seama cum de a bucla codul meu înapoi la un anumit punct, am 2 puncte de buclă și primul funcționează bine, dar eu nu pot obține cea de-a doua să lucreze cum trebuie să definească întreg variabila "num_stores_int" dar dacă nu, atunci "în timp ce" bucla nu funcționează. Codul meu de unde aceste puncte sunt.

Aici e codul meu:

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

Nu este foarte clar ceea ce sunteți în căutarea pentru, dar cred că-ți exterior while bucla este menit să păstreze cere utilizatorului pentru intrare atunci când au ceva de intrare care nu este numeric?

Aș singura folie care while buclă în jurul cod care cere pentru datele introduse de utilizator, după cum urmează:

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

Da, exterior buclă în timp ce este de lucru pentru mine, dar la interior nu e pentru că trebuie să definească întreg variabilă num_stores_int în scopul de a verifica dacă acesta este sub numărul 10, dar dacă o voi face, va avea deja o valoare definită și nu intrările de utilizator și deci nu merge
Weaver Ant

@Clandestinitate ai Putea fi mai specific cu privire la ceea ce nu funcționează cu codul ce l-am postat
Erik McKelvey

oooh trage nu am observat schimbarea și a crezut că ai postat din nou același cod. Wow, nu mă așteptam să lucreze. Vă mulțumesc foarte mult!!!
Weaver Ant

@Clandestinitate văd că ești nou la LUCRU. Dacă vă simțiți un răspuns rezolvat problema, vă rugăm să marcați-l ca "acceptat", făcând clic pe bifa verde. Acest lucru vă ajută să păstrați se concentreze pe mai vechi, DECI care încă nu au răspunsuri.
Erik McKelvey

Hopa, care evident xD, Mulțumesc am fost în căutarea pentru ceva pentru a-l marca ca raspunsul corect. Îmi pare rău, că e târziu și creierul meu este complet prajit XD
Weaver Ant

@Clandestinitate Toate bune, multumesc!
Erik McKelvey

yo scuze pentru anularea lucru am dat seama că nu rezolvă problema. E greșeala mea, i-am explicat prea bine dar am incercat ceva si a mers. Multumesc pentru ajutor oricum!
Weaver Ant

Cel mai bun răspuns

0

Greșeala mea, eu trebuie să fi prost explicat de ce a fost greșit, dar am incercat ceva si a mers.

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

În alte limbi

Această pagină este în alte limbi

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