2015-10-08 7 views
5

मैं अन्य पोस्ट पढ़ रहा हूं और इसे समझ नहीं पाया। कोई फर्क नहीं पड़ता कि मैं इस दोहराने के अंत में क्या दर्ज करता हूं यह हमेशा लूप को दोहराता है। मैंने while(repeat != "Quit" or repeat != "quit" or repeat != "b" or repeat != "B" or repeat != "no" or repeat != "No"): की कोशिश की है लेकिन यह अभी भी काम नहीं करता है। मुझे नहीं पता कि और क्या प्रयास करें। लूप के दौरान इसमें क्या गलत है?मेरा समय लूप क्यों नहीं रुकता है?

repeat = "d" 
    print "Please answer questions using the choices (A, B, C, etc.)" 
    time.sleep(2.1738) 
    while repeat != "Quit" or repeat != "quit" or repeat != "b" or repeat != "B" or repeat != "no" or repeat != "No": 
     print "A) Round Edges" 
     print "B) Straight Edges" 
     Edges1 = raw_input("Does the shape have round edges or straight edges?: ") 
     if Edges1 == "a" or Edges1 == "A" or Edges1 == "Round Edges" or Edges1 == "round edges": 
      print "A) Circle" 
      print "B) Semi-Circle" 
      Circle = raw_input("Is it a circle or semi-circle?: ") 
      if Circle == "A" or Circle == "a" or Circle == "Circle" or Circle == "circle": 
       radius_C = input("What is the radius (1/2 of the Diameter)?: ") 
       Area_C = math.pi * radius_C ** 2.0 
       Circum_C = 2.0 * math.pi * radius_C 
       Diameter_C = 2.0 * radius_C 
       print "The radius is " + str(radius_C) + ". " 
       time.sleep(.5) 
       print "The diameter is " + str(Diameter_C) + ". " 
       time.sleep(.5) 
       print "The circumference is " + str(round(Circum_C, 2)) + ". " 
       time.sleep(.5) 
       print "The area is " + str(round(Area_C, 2)) + ". " 
       time.sleep(5) 
      elif Circle == "B" or Circle == "b" or Circle == "Semi-Circle" or Circle == "semi-circle": 
       radius_S = input("What is the radius (1/2 of the Diameter)?: ") 
       Area_S = math.pi * radius_S ** 2.0 * .5 
       Diameter_S = 2 * radius_S 
       Per_S = ((math.pi * 2 * radius_S)/2) + Diameter_S 
       print "The radius is " + str(radius_S) + ". " 
       time.sleep(.5) 
       print "The diameter is " + str(Diameter_S) + ". " 
       time.sleep(.5) 
       print "The perimeter is " + str(round(Per_S, 2)) + ". " 
       time.sleep(.5) 
       print "The area is " + str(round(Area_S, 2)) + ". " 
       time.sleep(5) 
      else: 
       print "Incorrect input." 
     elif Edges1 == "b" or Edges1 == "B" or Edges1 == "Straight Edges" or Edges1== "straight edges": 
      sides = input("How many sides does the shape have?: ") 
      sideL = input("What is the length of 1 side?: ") 
      Area = round(Area_R(sides, sideL), 4) 
      Perim = round(Perm_R(sides, sideL), 4) 
      print "The area of this figure is: " + str(Area) 
      print "The perimeter of the figure is: " + str(Perim) 
     else: 
      print "Incorrect input." 


     time.sleep(4) 
     print" " 
     print" " 
     print "A) yes" 
     print "B) No" 
     repeat = raw_input("Want to try another?: ") 
     time.sleep(1) 
main() 
+3

मुझे लगता है कि आप का मतलब '' and' or' ... – ThiefMaster

उत्तर

7

ठीक है, उस स्थिति पर एक नज़र डालें:

while repeat != "Quit" or repeat != "quit" 

इसके बारे में सोचो। कोई फर्क नहीं पड़ता कि repeat का मान क्या है, यह हमेशा सत्य हैrepeat हमेशा "Quit"से या"quit" से अलग होगा। यदि यह एक है, तो यह दूसरा नहीं होगा।

आपको इसे "छोड़ें" और से "छोड़ने" से अलग होने की आवश्यकता है। अधिक कॉम्पैक्ट

while repeat != "Quit" and repeat != "quit" ... 

या,: इस प्रयास करें

while repeat.lower() not in ["quit", "b"] 
+0

वाह इस तरह उन्हें आसानी से ठीक करने के बजाय:/ –

+2

शायद, मैं देखा यह आसान है क्योंकि मैंने लूप में सभी कोड नहीं पढ़े - मुझे लगता है कि समस्या पहली या आखिरी पंक्तियों में होगी। अगली बार, जब आपको कोई समस्या नहीं मिलती है, ** उस समस्या का सबसे छोटा टुकड़ा टुकड़ा ढूंढें जिसमें समस्या है **, और उस पर हमला करें :) – slezica

+0

मदद के लिए धन्यवाद :) –

0

के साथ अपने या की और के बदलें इस तरह:

while repeat != "Quit" and repeat != "quit" and repeat != "b" and repeat != "B" and repeat != "no" and repeat != "No": 

यह हमेशा समान नहीं कम से कम उन चीजों में से एक रहा है। यह एक ही समय में दो चीजों के बराबर नहीं हो सकता है। यहां एक और छोटा उदाहरण दिया गया है (लेकिन ऊपर दिए गए मेरे सुझाव का प्रयास करें)।

# Never true 
repeat == "Quit" and repeat == "quit" 

# Never false 
repeat != "Quit" or repeat != "quit" 
संबंधित मुद्दे