- This event has passed.
5 PM – Python OOP – Gamas
August 10, 2025 @ 5:00 pm - 6:00 pm
Today We Did
- We reviewed For Loop and While Loop.
Homework
- This is how you convert from String to Integer
-
text = "20" text = int(text)
-
- All input from shell is a String data type.
- For example:
-
time = input("What time is it: ")
- When do you need to convert from String to Integer?
- When you need to do mathematical operations like addition, substraction, multiplication and division.
- Or when you want to check if something is greater than or less than.
- Example:
- Today’s coding where we check when it is morning, afternoon or evening.
- morning : time < 12
- lunch time : time == 12
- afternoon : time > 12 and tiem < 18
- evening: time > 18
- Today’s coding where we check when it is morning, afternoon or evening.
- Example:
- 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
-
name = input("What is your name: ")
-
- Memorize and try to understand below codes
-
# 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")