By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

continue "not properly in loop"

P: 7
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!


Expand|Select|Wrap|Line Numbers
  1.  
  2. question1 = "who was the first president of india?"
  3. option1 = "a.rajendraprasad"
  4. option2 = "b.sonia gandhi"
  5. option3 = "c.indira gandhi" 
  6. option4 = "d.jawaharlalnehru"
  7. print question1, option1,option2,option3,option4
  8.  
  9. first = raw_input("enter your answer!").lower()
  10. a = option1
  11. if first == 'a':
  12.         print 'you win!'
  13. else:
  14.     print 'you lose!'
  15.  
Attached Files
File Type: txt New Text Document (3).txt (362 Bytes, 445 views)
Jun 4 '11 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 621
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,
Expand|Select|Wrap|Line Numbers
  1. def ask_question(question):
  2.     print "-"*30
  3.     print question[0], "\n"
  4.     for ctr in range(1, len(question)-1):
  5.         print ctr, question[ctr]
  6.     print
  7.     first = raw_input("enter your answer! ")
  8.     if first == str(question[-1]):
  9.         print 'you win!'
  10.         return True
  11.  
  12.     print 'you lose!'
  13.     return False
  14.  
  15.  
  16. q_list = [ ["who was the first president of india?",
  17.             "rajendraprasad", "sonia gandhi", "indira gandhi", 
  18.             "jawaharlalnehru", 1],
  19.            ["What is 3 + 2?", "23", "5", "32", "1", 2] ]
  20.  
  21. ctr = 0
  22. result = True
  23. while result:
  24.     result = ask_question(q_list[ctr])
  25.     ctr += 1 
Jun 4 '11 #2

P: 7
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!
Jun 5 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.