Python IO Input/ Output Quiz
This is a small quiz which uses python for its inputs and outputs, and tests the player on the basic function of the python code.
import getpass, sys
def question_with_response (prompt) :
print("Question: "+ prompt)
msg = input()
return msg
# Define the number of correct answers and total questions
correct = 5 # Replace with the actual number of correct answers
questions = 5 # Replace with the total number of questions
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + "question.")
(question_with_response(" Are you ready to take a test?"))
rsp = question_with_response("Name the commmand used to install and manage software packages, written in the python language ")
if rsp == "pip":
print(rsp + " is correct")
correct += 1
questions += 1
else:
print(rsp + " is incorrect")
wrong =+ 1
questions += 1
rsp = question_with_response("Name the command used to check the type of class of an object in python ")
if rsp == "type":
print(rsp + " is correct")
correct += 1
questions += 1
else:
print(rsp + "is incorrect")
wrong =+ 1
questions =+ 1
rsp = question_with_response(" Name the command used to taken an input from the user in a dynamic code")
if rsp == "input":
print(rsp + " is correct")
correct += 1
questions += 1
else:
print(rsp + " is incorrect")
wrong =+ 1
questions =+ 1
rsp = question_with_response("Name the command used to get the number of items in a object ")
if rsp == "len":
print(rsp + " is correct")
correct += 1
questions += 1
else:
print(rsp + "is incorrect")
wrong += 1
questions += 1
rsp = question_with_response("Name the command used print a message on the screen in python ")
if rsp == "print":
print(rsp + " is correct")
correct += 1
questions += 1
else:
print( rsp + " is incorrect")
wrong += 1
questions += 1
# Calculate the percentage
percent = (correct / questions) * 100
# Print the result
print("Your percentage for this quiz is: {:.2f}%".format(percent))
Hello, srivaidyas running /opt/homebrew/opt/python@3.11/bin/python3.11
You will be asked 5question.
Question: Are you ready to take a test?
Question: Name the commmand used to install and manage software packages, written in the python language
pip is correct
Question: Name the command used to check the type of class of an object in python
type is correct
Question: Name the command used to taken an input from the user in a dynamic code
input is correct
Question: Name the command used to get the number of items in a object
len is correct
Question: Name the command used print a message on the screen in python
print is correct
Your percentage for this quiz is: 100.00%