Midterm Recap

Stats & Solutions

M. Lim
Intro to Programming
3 min readMar 9, 2018

--

Is there at least ONE thing you understand better now from taking the midterm? If so — you’ve succeeded, regardless of your score.

Average Score per Question: #1. Greet by Name | 6.2 (A)
#2. Total + Tax | 6.7 (A)
#3. Greet by Time | 5 (B)
#4. Password Loop | 4.4 (C)
#5. Twitter Bot | 3.1 (C)
___________________________
Overall Class Average: 5 (B)

#1. Greet by Name

Write a program that:

  • asks the name of the user
  • greets the user by name — IN ALL CAPITAL LETTERS.
# example by Fernandaname = input("What's your name? ")nameUPPERCASE = name.upper()print("HELLO " + nameUPPERCASE + "!!!")

#2. Total + Tax

Write a program that:

  • asks the user for the subtotal (price before tax)
  • asks the user for the current tax rate (in decimal form)
  • calculates the total price with tax
# example by Joeyprice = float(input("what is price before tax"))tax = float(input("what is current tax rate"))total = price + (price * tax)print("the total price is: " + str(total))

#3. Greet by Time

Write a program that:

  • asks for the current hour (in military time, 0–23)
  • prints a greeting, according to this algorithm:

HOUR | GREETING
7–11 | Good morning
12–16 | Good afternoon
17–23 | Good evening
0–3 | Go to bed!
4–6 | You’re up early
Any other number (including 24) is invalid

# example by Lidiahour = int(input("Enter the hour (in military time): "))if hour >= 7 and hour <= 11:
print("Good morning")
elif hour >= 12 and hour <= 16:
print("Good afternoon")
elif hour >= 17 and hour <= 23:
print("Good evening")
elif hour >= 0 and hour <= 3:
print("Go to bed!")
elif hour >= 4 and hour <= 6:
print("Youre up early")
else:
print("invalid input")

#4. Password Loop

Write a program that:

  • keeps asking the user for the password ("p@ssw0rd%"), until they get it right
  • prints a message whenever they get it wrong
  • prints a different message when they get it right
# example by Arthurpassword = "p@ssw0rd%"x = ''while x != password :

x = input("please enter your password")

if x == ("p@ssw0rd%"): # should use password variable here
print("access granted")

else :
print("access denied")

#5. Twitter Bot

Write a program that

  • takes text as input
  • checks how many characters there are
  • says whether or not it can be posted to Twitter, which has a 280 character limit
# example by Ryanstr = input("Enter text. ")if len(str) <= 280 :
print("OK to post. ")
else :
print("Too long to post. ")
# for best practices, the variable should be called something other than str, because someone might confuse it with the function str()

Extra Credit Opportunity

I sent back all problems that scored less than 4 points. For extra credit, comment out the code you wrote and then just type in the correct example. Type it, don’t copy/paste! And make sure to include the comment about who wrote it. Do the same for any problems you didn’t submit — just type it in, and give proper credit. The goal of this is to help you better understand the solutions through muscle memory.

--

--