American Young Coder

AYC logo
Loading Events

« All Events

  • This event has passed.

5 PM – Python OOP – Gamas

August 10 @ 5:00 pm - 6:00 pm

Today We Did
  1. We reviewed For Loop and While Loop.
Homework
  1. This is how you convert from String to Integer
    1. text = "20"
      text = int(text)
  2. All input from shell is a String data type.
    1. For example:
    2. time = input("What time is it: ")
  3. When do you need to convert from String to Integer?
    1. When you need to do mathematical operations like addition, substraction, multiplication and division.
    2. Or when you want to check if something is greater than or less than.
      1. Example:
        1. Today’s coding where we check when it is morning, afternoon or evening.
          1. morning : time < 12
          2. lunch time : time == 12
          3. afternoon : time > 12 and tiem < 18
          4. evening: time > 18
  4. If you are asking question to user (via shell) and the answer does not require a number, then you do not need to convert to Integer
    1. name = input("What is your name: ")
  5. Memorize and try to understand below codes
  6. # print Hello John 45 times
    # ASK USER to "enter a number"
    # Enter a number: 5
    # print Hello John 5 times
    number = input("Enter a number: ")
    number = int(number)
    for i in range(number):
        print("Hello John")
    
    
    # continuously ask user what time is it?
    # if user enter 12 then say "It is time to eat lunch" and then break
    # if user enter number below 12, then say "It is morning" just continue
    # if user enter number above 12, then say "It is afternoon" and
    # if user enter number above 18, then say "It is evening"
    # if user enter number below 0 or above 23 then say, "Invalid input"
    while True:
        time = input("What time is it: ")
        time = int(time)
        if time < 0 or time > 23:
            print("Invalid input")
        elif time < 12:
            print("It is morning")
        elif time == 12:
                print("It's time to eat lunch")
                break
        elif time > 12 and time < 18:
            print("It is afternoon")
        elif time > 18:
            print("It is evening")

Details

Date:
August 10
Time:
5:00 pm - 6:00 pm