#imports the libary
import getpass, sys 
import re 
#defines the function
#promt is the questions
def question_with_response(prompt):
    print("Question: " + prompt)
    msg = input()
    return msg
#variables
questions = 7
correct = 0
#into words
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
print("Are you ready to take a test?")

quest = [ "What command is used to include other functions that were previously developed?","What command is used to evaluate correct or incorrect response in this example?","Each 'if' command contains an '_________' to determine a true or false condition?","What key word in python defines a function?","What key word turns a variable into a string?","what command stores what the user types?","what command is followed b 'if'?"]

Answers = {
    "0" : ["import","Import"],
    "1" : ["if", "If"],
    "2" : ["expression","Expression"],
    "3" : ["def","Def"],
    "4" : ["str","Str"],
    "5" : ["input","Input"],
    "6" : ["else","Else"]
}

q = -1

while q <6:
    q += 1
    rsp = question_with_response(quest[q])
    if re.search(r'\d', rsp) :
        print(" Input must not contain a number")
    else:
        if rsp in Answers[str(q)]:
            print( rsp + " is correct")
            correct += 1
        else:
                print( rsp +(" is incorrect"))
        
          

# the value in the variable correct is divided by the value in the variable question and then multiplied by 100
# this value is saved in the variable percentage
percentage = correct/questions *100

if percentage < 50:
    print(getpass.getuser() + " You failed")
else:
    print(getpass.getuser() +" You passed")


#getpass.getuser() takes the user name  and str converts the variable correct into a string
#this is the same with the variable question
print( " you scored " + str(correct) +"/" + str(questions))
print("or " + str(percentage) +"%")
# To show the percentage, the calculated value in the variable "percentage" then convert into a string 
Hello, varunm running /bin/python
You will be asked 7 questions.
Are you ready to take a test?
Question: What command is used to include other functions that were previously developed?


IMPORT is incorrect
Question: What command is used to evaluate correct or incorrect response in this example?

Example of Output

# example of Output in this code

print("Are you ready to take a test?")

This code prints out “Are you ready to take a test?

Example of Input with output

# example of Input and Output in this code
def question_with_response(prompt):
    print("Question: " + prompt)
    msg = input()
    return msg

In this code the user input is stored the in the variable msg. It also prints out “questions:” with a prompt

Example of a List in this program

# example of a list in this program
quest = [ "What command is used to include other functions that were previously developed?","What command is used to evaluate correct or incorrect response in this example?","Each 'if' command contains an '_________' to determine a true or false condition?","What key word in python defines a function?","What key word turns a variable into a string?","what command stores what the user types?","what command is followed b 'if'?"]

In this code, the all the questions/prompts are in a list

Example of a dictinary in this program

# example of a dictionary in this program
Answers = {
    "0" : ["import","Import"],
    "1" : ["if", "If"],
    "2" : ["expression","Expression"],
    "3" : ["def","Def"],
    "4" : ["str","Str"],
    "5" : ["input","Input"],
    "6" : ["else","Else"]
}

In this code, all the answers are organized per question in dictionary

Example of a Iteration

# Example of Iteration in this code
q = -1

while q <6:
    q += 1
    rsp = question_with_response(quest[q])
    if rsp in Answers[str(q)]:
        print( rsp + " is correct")
        correct += 1
    else:
        print( rsp +(" is incorrect"))

In this code, a while loop is used to simplify the code. It uses logic to loop the code until the number of questions runs out.

Example of a function that performs mathematical calculations

# example of a function to perform mathematical and/or a statistical calculations.
percentage = correct/questions *100

In this code, the percentage is found using the # of questions the user got correct, dividing it by the total number of questions and multiplying that by 100

Example of a function with a selection/condition

# example of a function with a Selection/Condition
if rsp in Answers[str(q)]:
        print( rsp + " is correct")
        correct += 1
    else:
        print( rsp +(" is incorrect"))

In this code, it checks if the user input is correct. The conditions is, if the user is correct, then it prints out that the input is correct, but if it is wrong, the code prints out that the input is incorrect