not allowing me to input and loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gus1
    New Member
    • Dec 2012
    • 1

    not allowing me to input and loop

    Code:
    def quiz():
        for count in range(1):
            import time
            print ("hello and welcome to my input output quiz")
            time.sleep(2)
            print()
            print("INTRUCTIONS")
            time.sleep(2)
            print()
            print(" you will a choice of 4 possible answers to chose from")
            print("you will have 20 second to choose.please answer in lower case")
            start =input("Are you ready to start Y/N :  ")
            if start == "y":
                print("QUESTION 1")
                print()
                Q1=input("which one of these is NOT an import device ? ")
            if Q1 == "B" or Q1 == "b":
                    print ("correct, next question")
            else:
                        print("incorrect, please try again")
                        # loop before question ? how ever you do that?
                        print()
                        time.sleep(2)
                        print("A: keyboard")
                        ()
                        print("B: usb")
                        ()
                        print("C: Mouse")
                        ()
                        print("D: Joystick")
                        ()
                        time.sleep(20)
                        if count == 0:
                            print ("times up, please try again")
                            # loop
    Last edited by Gus1; Dec 18 '12, 06:39 PM. Reason: python 2.7
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Your import statement should be at the top of the file. To loop until the question is answered, try something like this:
    Code:
    >>> while True:
    ... 	s = raw_input("Input 'X'")
    ... 	if s.lower() == "x":
    ... 		break
    ... 	print "Wrong! Try again"
    ... 	
    Wrong! Try again
    >>>
    You have to call your function as in:
    Code:
    quiz()

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

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

      Comment

      Working...