ปัญหาการวนรอบจะจุดในข้อมูลการตรวจสอบรหัส

0

คำถาม

ฉันไม่สามารถที่จะคิดหาวิธีของฉันรหัสลับไปเป็นเจาะจงประเด็นฉันมี 2 วงคะแนนและคนแรกทำงานสบายดีแต่ฉันไม่สามารถเอาอันที่สองทำงานอย่างที่ฉันต้องกำหนดจำนวนเต็มตัวแปร"num_stores_int"แต่ถ้าผมทำอย่างนั้น"ขณะที่"วงไม่ได้ผลหรอก เห็นของรหัสสำหรับพวกนั้นอยู่ไหนคะแนน

นี่คือของฉันรหัส:

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 เรื่องก็คือตั้งใจจะให้ของของผู้ใช้สำหรับนำเข้าข้อมูลตอนที่พวกเขานำเข้าข้อมูลบางอย่างนั่นไม่ใช่ numeric?

ฉันจะห่อมัน 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

ใช่คริงๆข้างในขณะที่วงกำลังทำงานสำหรับฉันแต่งๆภายในหนึ่งไม่ใช่เพราะฉันต้องกำหนดจำนวนเต็มตัวแปร num_stores_int เพื่อที่จะตรวจสอบว่ามันอยู่ใต้เบอร์ 10 แต่ถ้าฉันทำมันไปแล้วถูกกำหนดค่าและไม่ใช่หนึ่งของผู้ใช้ inputs และดังนั้นไม่ได้ผล
Weaver Ant

@Clandestinity เธอช่วยเจาะจงกว่านี้ได้เกี่ยวกับสิ่งที่ไม่ได้ทำงานกับครอบครหัสฉันโพสต์
Erik McKelvey

โอ้ยิงฉันไม่ได้สังเกตเห็นคนเปลี่ยนแปลงและคิดว่าคุณแค่ reposted ของฉันเดียวกันเป็นรหัสมอส ว้าวผมไม่ได้คาดหวังให้ไปทำงานแล้ว ขอบคุณมากเพื่อน!!
Weaver Ant

@Clandestinity ฉันเห็นคุณใหม่เพื่ออย่างนั้น ถ้าคุณรู้สึกอคำตอบแก้ปัญหาได้โปรดมาร์กมันเป็น'ยอมรับ'โดยการคลิกที่กรีนเครื่องหมาย. มันจะช่วยสมองโตขึ้นดังนั้นซึ่งยังไม่มีคำตอบ
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ý
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่