continue "not properly in loop"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sourabh mittal
    New Member
    • Jun 2011
    • 7

    continue "not properly in loop"

    hi guys! i'm successful in creating my first kbc game with one question with integers and strings as input!well i'm a strater and please help because i want to loop it with break if lose and continue with win after first question.simply i want to continue it and want to know how?please give me the modified script so i can move in my project!here's the script!pls help!


    Code:
         
    question1 = "who was the first president of india?"
    option1 = "a.rajendraprasad"
    option2 = "b.sonia gandhi"
    option3 = "c.indira gandhi" 
    option4 = "d.jawaharlalnehru"
    print question1, option1,option2,option3,option4
    
    first = raw_input("enter your answer!").lower()
    a = option1
    if first == 'a':
            print 'you win!'
    else:
    	print 'you lose!'
    Attached Files
    Last edited by Niheel; Jun 4 '11, 01:15 PM. Reason: always use code tags to show code
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    I would suggest a list of questions sent to a function. This is very basic so if you do not understand any of this check one of the online books, since it is impossible to guess how much Python you know,
    Code:
    def ask_question(question):
        print "-"*30
        print question[0], "\n"
        for ctr in range(1, len(question)-1):
            print ctr, question[ctr]
        print
        first = raw_input("enter your answer! ")
        if first == str(question[-1]):
            print 'you win!'
            return True
    
        print 'you lose!'
        return False
    
    
    q_list = [ ["who was the first president of india?",
                "rajendraprasad", "sonia gandhi", "indira gandhi", 
                "jawaharlalnehru", 1],
               ["What is 3 + 2?", "23", "5", "32", "1", 2] ]
    
    ctr = 0
    result = True
    while result:
        result = ask_question(q_list[ctr])
        ctr += 1

    Comment

    • sourabh mittal
      New Member
      • Jun 2011
      • 7

      #3
      thank you very much now i can complete my project at kbc game and i will upload it and give you a large credit!please me connected to help me in more projects!

      Comment

      Working...