Проблема с переходом к точке в коде проверки ввода

0

Вопрос

Я не смог понять, как зациклить свой код до определенной точки, у меня есть 2 точки цикла, и первая работает нормально, но я не могу заставить работать вторую, так как мне нужно определить целочисленную переменную "num_stores_int", но если я это сделаю, то цикл "while" не работает. Посмотрите мой код, где находятся эти точки.

Вот мой код:

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

Не совсем понятно, что вы ищете, но я считаю, что ваш внешний while цикл предназначен для того, чтобы продолжать запрашивать у пользователя ввод, когда он вводит что-то не числовое?

Я бы только завернул это while выполните цикл вокруг кода, запрашивающего ввод данных пользователем, следующим образом:

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

Да, внешний цикл while работает для меня, но внутренний-нет, потому что я должен определить целочисленную переменную num_stores_int, чтобы проверить, находится ли она под номером 10, но если я это сделаю, она примет уже определенное значение, а не то, которое вводит пользователь, и поэтому не работает
Weaver Ant

@Clandestinity Не могли бы вы уточнить, что не работает с кодом, который я опубликовал
Erik McKelvey

оооо, я не заметил изменений и подумал, что ты просто перепостил мой тот же код. Вау, я не ожидал, что это сработает. Большое тебе спасибо, парень!!
Weaver Ant

@Подполье, я вижу, ты новичок в этом. Если вы считаете, что ответ решил проблему, пожалуйста, отметьте его как "принято", щелкнув зеленую галочку. Это помогает сосредоточиться на более старых вопросах, на которые все еще нет ответов.
Erik McKelvey

Уйма этого очевидного xD, Спасибо, что я искал что-то, чтобы отметить это как правильный ответ. Извини, уже поздно, и мой мозг полностью сгорел XD
Weaver Ant

@Clandestinity Все хорошо, спасибо!
Erik McKelvey

йо, извини, что отменил то, что я только что понял, что это не решило проблему. Это моя вина, я плохо объяснил, но я просто попробовал кое-что, и это сработало. В любом случае, спасибо вам за помощь!
Weaver Ant

Лучший ответ

0

Моя вина, я, должно быть, плохо объяснил, что было не так, но я просто попробовал кое-что, и это сработало.

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

На других языках

Эта страница на других языках

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