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

not allowing me to input and loop

P: 1
Expand|Select|Wrap|Line Numbers
  1. def quiz():
  2.     for count in range(1):
  3.         import time
  4.         print ("hello and welcome to my input output quiz")
  5.         time.sleep(2)
  6.         print()
  7.         print("INTRUCTIONS")
  8.         time.sleep(2)
  9.         print()
  10.         print(" you will a choice of 4 possible answers to chose from")
  11.         print("you will have 20 second to choose.please answer in lower case")
  12.         start =input("Are you ready to start Y/N :  ")
  13.         if start == "y":
  14.             print("QUESTION 1")
  15.             print()
  16.             Q1=input("which one of these is NOT an import device ? ")
  17.         if Q1 == "B" or Q1 == "b":
  18.                 print ("correct, next question")
  19.         else:
  20.                     print("incorrect, please try again")
  21.                     # loop before question ? how ever you do that?
  22.                     print()
  23.                     time.sleep(2)
  24.                     print("A: keyboard")
  25.                     ()
  26.                     print("B: usb")
  27.                     ()
  28.                     print("C: Mouse")
  29.                     ()
  30.                     print("D: Joystick")
  31.                     ()
  32.                     time.sleep(20)
  33.                     if count == 0:
  34.                         print ("times up, please try again")
  35.                         # loop
Dec 18 '12 #1
Share this Question
Share on Google+
2 Replies

bvdet
Expert Mod 2.5K+
P: 2,851
Your import statement should be at the top of the file. To loop until the question is answered, try something like this:
Expand|Select|Wrap|Line Numbers
  1. >>> while True:
  2. ...     s = raw_input("Input 'X'")
  3. ...     if s.lower() == "x":
  4. ...         break
  5. ...     print "Wrong! Try again"
  6. ...     
  7. Wrong! Try again
  8. >>> 
You have to call your function as in:
Expand|Select|Wrap|Line Numbers
  1. quiz()
Dec 18 '12 #2

Expert 100+
P: 626
You don't ever change "count" so this statement will execute every time
Expand|Select|Wrap|Line Numbers
  1.                    if count == 0:
  2.                         print ("times up, please try again") 
You perhaps want something more like
Expand|Select|Wrap|Line Numbers
  1. if number_of_tries > maximum_allowed:
  2.     return False  ## exit the function 
And we usually say input device in the US but it may be different where you are.
Expand|Select|Wrap|Line Numbers
  1.  Q1=input("which one of these is NOT an import device ? ") 
Dec 19 '12 #3

Post your reply

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