Python Week 1
Jack Pordi,  5 February 2018

Python Week 1 Challenges

These are a series of challenges that may be useful for you to practice what you've learnt in each session. If you manage to complete all of them, then well done! All of the following can be done with just what we've taught you this week - but if you're ambitious, do feel free to do some googling and learning on your own! At the start of next session, if enough people request, we can go through some of these as well.

#1: Marco Polo

  • Write a simple program that “checks” the user’s response.
  • For example, have the program call out (print) Marco, and the user must respond. If the response is exactly Polo, then the program responds with something nice. If the response is incorrect, tells the user to go away.
  • BONUS: Ignore upper-case/lower-case errors, so allow polo, POLO, pOlO.....etc. Would you say the way you've done it is a good way?

#2: Basic Calculator

  • When the program starts, asks what the user wants to do. If the user inputs add, then ask the user to input two numbers and adds them.
  • Do the same for subtract, multiply and divide.

#3: Math Quiz

  • Print out a math question. For example, 4 x 4 = ?. Then, have a user input an answer.
  • If the user is correct, congratulate them, and move on to another question. If the user is wrong, then move on to the next question anyways.
  • At the end of the quiz, print out the user's score, either as a percentage, or as a mark out of number of questions, or both. For example, 55% or 8/10.
  • BONUS: At the end of the quiz, output the questions that the users got wrong, and reveal the answer. Hint: you'll need a way to "remember" which answers the user got wrong.

#4: Valid Dates

  • The user inputs a date, month, and a year.
  • Tells the user if the input date is valid (e.g. February 31st would never be valid, nor would June 31st, etc)
  • You will have to check for leap years.

#5: Valid Triangle (Somewhat Hard)

  • The user inputs 3 numbers (one at a time), each specifying the length of a side of a triangle. You cannot assume anything about the order of the numbers that were input.
  • Check whether the 3 sides form a valid triangle, and tell the user.
  • Hint: you'll need a way to look at which side is the biggest, and the smallest. We'll cover a more general (and significantly better) way of sorting later, but for now you'll need to find a way to sort 3 numbers. Another hint: This will require a pretty large number of if and elif or else statements.

More Challenges Coming soon!