American Young Coder

AYC logo
Loading Events

« All Events

  • This event has passed.

3 PM – Python OOP – Gamas

August 16 @ 3:00 pm - 4:00 pm

Homework
  1. Memorize when you should convert from String to Integer. When you get an input from Shell and you need to do
    1. Mathematical operations: addition, substraction, division and multiplication
    2. when you need to check if it is greater than or less than
  2. Finish aug_16_simple_calculator.py program
    1. """
      SIMPLE CALCULATOR
      1. continously ask user for 2 numbers
      2. After user enter 2 numbers, then add them up and display the result
         of addition
         
      Example
      Enter first number: 1
      Enter second number: 2
      Result, 1 + 2 = 3 
      
      Enter first number: 100
      Enter second number: 1
      Result, 100 + 1 = 101
      
      
      """
  3. Understand and memorize below code
  4. """
    1. Create a random number between 1 to 100
    2. Ask user guess a number between 1 to 100.
    3. If user guess a number that less than the number that is generated in step 1, then print, "the number is too small."
    4. If user enter a number that is bigger than the number that is generated in step 1, then print, "the number is too big."
    5. if user enter a number that is equal to step 1, then print "congrats you guess the number correctly" And stop the loop
    """
    
    import random as r
    random_num = r.randint(1,100)
    while True:
        number = input("Guess a number between 1 to 100: ")
        number = int(number)
        if number > 100 or number < 1:
            print("Invalid")
        elif number < random_num:
            print("The number is too small")
        elif number > random_num:
            print("The number is too big")
        else:
            print("Congrats, you guess the number correctly")
            break

Details

Date:
August 16
Time:
3:00 pm - 4:00 pm