• toc: true
  • comments: true
  • permalink: /chesscode/cool
  • categories: [chesscode]

Chess is cool

This is a Chess quiz: 3 questions shall be asked. Try to get them all correct.

import getpass, sys

def question_and_answer(prompt):
    print("Question: " + prompt)
    msg = input()
    print("Answer: " + msg)

questions = 3
correct = 0

print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_and_answer("Are you ready to take a test?")

def question_with_response(prompt):
    print("Question: " + prompt)
    msg = input()
    return msg



rsp = question_with_response("What is a king?")
if rsp == "main piece in chess":
    print(rsp + " is correct!")
    correct += 1
else:
    print("That is incorrect!")

rsp = question_with_response("Where is the queen placed?")
if rsp == "next to the king":
    print(rsp + " is correct!")
    correct += 1
else:
    print("That is incorrect!")

rsp = question_with_response("Where is the rook placed?")
if rsp == "at the ends of the board":
    print(rsp + " is correct!")
    correct += 1
else:
    print("That is incorrect!")

print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
Hello, shreyas running /home/shreyas/anaconda3/bin/python
You will be asked 3 questions.
Question: Are you ready to take a test?
Answer: yes
Question: What is a king?
That is incorrect!
Question: Where is the queen placed?
That is incorrect!
Question: Where is the rook placed?
That is incorrect!
shreyas you scored 0/3