Hello to Python

print("Hello World!")
Hello World!
msg = "Greetings"
print(msg)
Greetings
def question_and_answer(prompt):
    print("Question: " + prompt)
    msg = input()
    print("Answer: " + msg)

question_and_answer("Name the Python output command mentioned in this lesson?")
question_and_answer("If you see many lines of code in order, what would College Board call it?")
question_and_answer("Describe a keyword used in Python to define a function?")
Question: Name the Python output command mentioned in this lesson?
Answer: Print
Question: If you see many lines of code in order, what would College Board call it?
Answer: Source Lines of Code (SLOC)
Question: Describe a keyword used in Python to define a function?
Answer: def

Answers to Hacks

Test running a Python file directly

from IPython.display import Image
from IPython.core.display import HTML
Image(url= "https://raw.githubusercontent.com/Azeem-Khan1/fastpages-project/master/images/quizpy%20snip.jpg")

Making a Quiz

Pseudocode

  • PROCEDURE question_with_response (question)
    • DISPLAY question
    • response <-- input
    • RETURN response
  • questions <-- 5
  • correct <-- 0
  • DISPLAY Hello {user}, welcome to the Python quiz!
  • DISPLAY You will be asked {# of questions} questions
  • DISPLAY All answers are to be in lower case only
  • rsp <-- question_with_response(question)
  • IF (rsp == answer)
    • DISPLAY rsp is correct!
      • correct <-- correct +1
    • ELSE
      • DISPLAY rsp is incorrect :(
  • rsp <-- question_with_response(question)
  • IF (rsp == answer)
    • DISPLAY rsp is correct!
      • correct <-- correct +1
    • ELSE
      • DISPLAY rsp is incorrect :(
  • rsp <-- question_with_response(question)
  • IF (rsp == answer)
    • DISPLAY rsp is correct!
      • correct <-- correct +1
    • ELSE
      • DISPLAY rsp is incorrect :(
  • rsp <-- question_with_response(question)
  • IF (rsp == answer)
    • DISPLAY rsp is correct!
      • correct <-- correct +1
    • ELSE
      • DISPLAY rsp is incorrect :(
  • rsp <-- question_with_response(question)
  • IF (rsp == answer)
    • DISPLAY rsp is correct!
      • correct <-- correct +1
    • ELSE
      • DISPLAY rsp is incorrect :(
  • percent <-- str(round(correct/questions), 1)
  • DISPLAY {user}, you scored {str(correct) / str(questions)}
  • DISPLAY percent
  • DISPLAY Hope you enjoyed!
import getpass, sys # import necessities


def question_with_response(prompt): # function that allows for checking of correct response
    print("Question: " + prompt)
    msg = input()
    return msg

questions = 5
correct = 0

print('Hello, ' + getpass.getuser() + ", welcome to the Python quiz!") # introduction
print("You will be asked " + str(questions) + " questions.")
print("All answers are to be in lower case only")

rsp = question_with_response("What is it called when a value or function is assigned to an easy-to-remember word?") # define the question that is being asked
if rsp == "variable": # if the user's answer matches the correct one, then...
    print(rsp + " is correct!")
    correct += 1 # add 1 point
else: # if not...
    print(rsp + " is incorrect :(")

rsp = question_with_response("What command is used to include other functions that were previously developed?") # define the question that is being asked
if rsp == "import": # if the user's answer matches the correct one, then...
    print(rsp + " is correct!")
    correct += 1 # add 1 point
else: # if not...
    print(rsp + " is incorrect :(")

rsp = question_with_response("Each 'if' command contains an '_________' to determine a true or false condition?") # define the question that is being asked
if rsp == "expression": # if the user's answer matches the correct one, then...
    print(rsp + " is correct!")
    correct += 1 # add 1 point
else: # if not...
    print(rsp + " is incorrect :(")

rsp = question_with_response("What command is used to evaluate correct or incorrect response in this example?") # define the question that is being asked
if rsp == "if": # if the user's answer matches the correct one, then...
    print(rsp + " is correct!")
    correct += 1 # add 1 point
else: # if not...
    print(rsp + " is incorrect :(")

rsp = question_with_response("What is grouping a sequence of commands, often used repeatedly, called?") # define the question that is being asked
if rsp == "procedural abstraction": # if the user's answer matches the correct one, then...
    print(rsp + " is correct!")
    correct += 1 # add 1 point
else: # if not...
    print(rsp + " is incorrect :(")

percent = str(round(correct/questions, 1)*100) # calculate percentage by dividing # of correct answers by # of questions (round to the tenths place)

print(getpass.getuser() + ", you scored " + str(correct) +"/" + str(questions)) # show score (# of correct / # of questions)
print(f"Congratulations! That's a(n) {percent}%!") # show percentage

print("Hope you enjoyed!")
Hello, azeemk, welcome to the Python quiz!
You will be asked 5 questions.
All answers are to be in lower case only
Question: What is it called when a value or function is assigned to an easy-to-remember word?
variable is correct!
Question: What command is used to include other functions that were previously developed?
import is correct!
Question: Each 'if' command contains an '_________' to determine a true or false condition?
print is incorrect :(
Question: What command is used to evaluate correct or incorrect response in this example?
if is correct!
Question: What is grouping a sequence of commands, often used repeatedly, called?
procedural abstraction is correct!
azeemk, you scored 4/5
Congratulations! That's a(n) 80.0%!
Hope you enjoyed!