Hacks Assignments - Shreya Sapkal

Conditionals:

  • Write a program that fits these conditions using nested conditionals:
    • If the product is expired, print "this product is no good"
    • If the cost is above 50 dollars, and the product isn't expired, print "this product is too expensive"
    • If the cost is 25 dollars but under 50, and the product isn't expired, print "this is a regular product"
    • If the cost is under 25 dollars, print "this is a cheap product"
# Here is a python template for you to use.

expired = False
cost = 50
if expired == True: 
    print("This product is no good!")
else:
    if cost > 50:
        print("This product is too expensive!")
    elif cost >= 25:
        print("This is a regular product!")
    else:
        print("This is a cheap product!")
This is a regular product!

Boolean/Conditionals:

  • Create a multiple choice quiz that ...
    • uses Boolean expressions
    • uses Logical operators
    • uses Conditional statements
    • prompts quiz-taker with multiple options (only one can be right)
    • has at least 3 questions
  • Points will be awarded for creativity, intricacy, and how well Boolean/Binary concepts have been intertwined
import getpass, sys

def question_with_response(prompt): # use of a function
    print("Question: " + prompt)
    msg = input()
    return msg

questions = 3
correct = 0
question_and_answer = input 

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

rsp = question_with_response("What year was the last major recession in the US? | a) 2008 | b) 2010 | c) 2020")
if rsp == "a":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect! The correct answer was a")

rsp = question_with_response("Who recently bought Twitter? | a) Jeff Bezos | b) Elon Musk | c) Oprah Winfrey")
if rsp == "b":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect! The correct answer was b")

rsp = question_with_response("What element causes the sky to look blue? | a) Oxygen | b) Nitrogen | c) Carbon")
if rsp == "b":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect! The correct answer was b")

print(" you scored " + str(correct) +"/" + str(questions))
Hello, shreyasapkal
You will be asked 3 questions.
Question: What year was the last major recession in the US? | a) 2008 | b) 2010 | c) 2020
a is correct!
Question: Who recently bought Twitter? | a) Jeff Bezos | b) Elon Musk | c) Oprah Winfrey
c is incorrect! The correct answer was b
Question: What element causes the sky to look blue? | a) Oxygen | b) Nitrogen | c) Carbon
b is correct!
 you scored 2/3