Demo entry 1469413

main.py

   

Submitted by C on Mar 18, 2015 at 17:29
Language: Python 3. Code size: 1.4 kB.

# Main file for task 1
from question import Question
from student import Student

# Global Variables
number_of_questions = 10 # Number of question to be asked
counter = 0 # Counter for question loop
score = 0 # The users score
student = Student("") # A student object 
name_is_correct = False # Variable to store if name_is_correct is correct
question = Question() # Create new question object

# Name logic
# Iterate until True
while name_is_correct == False:
    name = input("Please enter your name:\n") # Ask user for name
    student.set_name(name) # Change student name
    result = student.is_valid() # Set name_is_correct to True if name is valid otherwise set it to False
    name_is_correct = result["result"]
    print(result["message"])

# Question Logic
while counter < number_of_questions:
    question.generate() # Generate new question and answer
    print("Question: " + question.get_question_text()) # Ouput question
    answer = input("Answer: ") # Input answer
    if question.is_correct(answer): # Check if answer is correct
        print("Correct!") # Output correct
        score = score + 1 # Add one to score
    else:
        print("Wrong!") # Output wrong
    # Increment counter
    counter = counter + 1

# print score
print("You scored: ")
print(str(score) + " / " + str(number_of_questions))

# wait for user to exit
input("Press RETURN to exit")

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).