We were able to utilize our pre-requisite, knowledge of functions to create a set of questions and answers in a more optimal fashion where it is less lines of code and looks more aesthetic to the eye.
importgetpass,sys,osdefask_question(question,correct_answer):user_response=input(f"Question: {question}\nYour Answer: ")ifuser_response.lower()==correct_answer.lower():print(f"Correct!\n")return1else:print(f"Sorry, that's incorrect. The correct answer is: {correct_answer}\n")return0defmain():questions=[("Is Python a programming language?","yes"),("Can you store multiple values in a list?","yes"),("Does Python use indentation to define code blocks?","yes"),]print(f"Hello, {getpass.getuser()} running {sys.executable}")print(f"You will be asked {len(questions)} questions.")input("Press Enter to start the test...")correct_count=sum(ask_question(q,a)forq,ainquestions)percentage=(correct_count/len(questions))*100print(f"{getpass.getuser()}, you scored {correct_count}/{len(questions)} which is {percentage:.2f}%.")if__name__=="__main__":main()