Giriş doğrulama kodunda bir noktaya döngü sorunu

0

Soru

Kodumu belirli bir noktaya nasıl geri döndüreceğimi bulamadım, 2 döngü noktam var ve ilki iyi çalışıyor, ancak "num_store_int" tamsayı değişkenini tanımlamam gerektiğinden ikincisini çalıştıramıyorum ama eğer yaparsam, o zaman" while " döngüsü çalışmıyor. O noktaların nerede olduğuna dair koduma bakın.

İşte kodum:

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

Ne aradığın çok net değil, ama dış görünüşün olduğuna inanıyorum. while döngü, sayısal olmayan bir şey girdiklerinde kullanıcıdan girdi istemeye devam etmek içindir?

Sadece bunu paketlerdim. while kullanıcı girişi isteyen kodun etrafında aşağıdaki gibi döngü yapın:

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

Evet, dış while döngüsü benim için çalışıyor ama iç olan, 10 sayısının altında olup olmadığını kontrol etmek için num_store_int tamsayı değişkenini tanımlamam gerektiğinden değil, eğer yaparsam, kullanıcının girdiği değeri değil, önceden tanımlanmış değeri alır ve bu yüzden çalışmaz
Weaver Ant

@Clandestinity Gönderdiğim kodla neyin işe yaramadığı konusunda daha spesifik olabilir misiniz
Erik McKelvey

oooh shoot Değişikliği fark etmedim ve aynı kodumu tekrar gönderdiğini düşündüm. Bunun işe yaramasını beklemiyordum. Seni o kadar çok adam ederim!!
Weaver Ant

@ Clandestinity So'da yeni olduğunu görüyorum. Bir cevabın sorunu çözdüğünü düşünüyorsanız, lütfen yeşil onay işaretini tıklatarak 'kabul edildi' olarak işaretleyin. Bu, hala cevapları olmayan yaşlılara odaklanmaya yardımcı olur.
Erik McKelvey

Bu bariz xD, teşekkürler, doğru cevap olarak işaretleyecek bir şey arıyordum. Üzgünüm, geç oldu ve beynim tamamen kızarmış XD
Weaver Ant

@ Clandestinity Hepsi iyi, teşekkür ederim!
Erik McKelvey

sorunu çözmediğini fark ettiğim şeyi iptal ettiğim için özür dilerim. Bu benim hatam, kötü açıkladım ama bir şey denedim ve işe yaradı. Yine de yardımın için teşekkürler!
Weaver Ant

En iyi cevabı

0

Benim hatam, neyin yanlış olduğunu kötü bir şekilde açıklamış olmalıyım ama sadece bir şey denedim ve işe yaradı.

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

Diğer dillerde

Bu sayfa diğer dillerde

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