Skip to content

Introduction to Python — Session 3

In this session we cover:

  • If / elif / else conditionals
  • Indenting
  • Comparators
  • And / Or / Not

Write your code

Questions

Section A

  1. Ask for the user's name, if they are called "Bob", print "Welcome Bob!"
  2. Ask for the user's name, if they are not called "Alice", print "You're not Alice!"
  3. Ask the user for a password, if they enter the password "qwerty123", print "You have successfully logged in". If they get it wrong, print "Password failure"
  4. Ask the user to enter a number, if the number is even, print "Even", otherwise print "Odd"
  5. Ask the user for 2 different numbers, if the total of the two numbers is over 21, print "Bust" otherwise print "Safe"
  6. Ask the user to enter the length and width of a shape and check if it is a square or not.
  7. You have had a great year and are going to offer a bonus of 10% to any employee who has a service of over 3 years. Ask the user to input their current salary and years of service and print out their salary and their bonus or "No bonus" if they are not receiving one.
  8. Take a whole number input, if it's positive, print out the number cubed, if it is a negative, print out half its value.

Section B

  1. Ask for the user's name, if they are called "Alice" print "Hello, Alice", if they are called "Bob", print "You're not Bob! I'm Bob", else print "You must be Charlie"
  2. Ask the user to enter their age
    1. If they are younger than 11, print "You're too young to go to this school"
    2. If they are between 11 and 16, print "You can can come to this school"
    3. If they are over 16, print 'You're too old for school"
    4. If they are 0, print "You're not born yet!"
  3. Ask the user to enter the name of a month. If the user enters March/April/May: print "month is in Spring", otherwise print "I don't know"
    1. Expand for the rest of the year, given that summer is June/July/August. Autumn is September/October/November. Winter is December/January/February
    2. Ensure that when an unknown month is given it prints "I don't know"
  4. Ask the user for two different numbers, if both numbers are even, print "Even", if both numbers are odd, print "Odd", else print the product of the two numbers
  5. Ask the user to input two numbers. Decide which is the number of highest value and print this out.
  6. You have had a fantastic year and are now going to offer a bonus of 20% to any employee who has a service of over 7 years, a bonus of 15% to any employee who has a service of over 5 years and a bonus of 10% to any employee who has a service of 3 - 5 years. Ask the user to input their current salary and years of service and print out their salary and their bonus or "No bonus" if they are not receiving one.
  7. Take the age and name of three people and determine who is the oldest and youngest and print out the name and age of the oldest and youngest. If all three ages are the same, print that.
  8. A school has following rules for their grading system:
    1. Above 80 – A
    2. 60 to 80 – B
    3. 50 to 60 – C
    4. 45 to 50 – D
    5. 25 to 45 – E
    6. Below 25 - F

Ask user to enter the lesson and the marks for three lessons and print out the corresponding grades for the lesson.

Answers

See the code for each answer on our GitHub!