Blog Detail

September 1, 2023

Python Operators Exercises

  • Check if the gadget is affordable or not ?

                    my_budget = 120.00
    gadget_price = 80.50
    
    is_gadget_affordable = my_budget '' gadget_price
    
    print('Is gadget affordable?', is_gadget_affordable)
    == >= <=
  • If the number of seats matches the industry standard, return True; otherwise, return False.

                    number_of_seats = 105
    standard_seats = 100
    
    is_standard = number_of_seats '' standard_seats
    
    print('Is the standard met?', is_standard)
    >= <= ==
  • Check if the guaranty is still valid ?

                    guranty_days = 60
    passed_days = 42
    
    is_guaranty_valid = guranty_days - passed_days '' 0
    
    print(f'Is the guaranty valid? {is_guaranty_valid}')
  • A university requires a minimum GPA of 3.5 for admission to its honors program.
    Check to determine if a student’s GPA meets the requirement for the honors program or not?

                    minimum_gpa_requirement = 3.5 
    student_gpa = 4.1 
    
    is_gpa_sufficient = student_gpa '' minimum_gpa_requirement
    
    print(is_gpa_sufficient)
    < <= > >=
  • A credit card company provides a special interest rate for customers with a credit score below 1000.
    Check if a customer’s credit score meets the requirement for the special interest rate or not?

                    special_interest_rate_threshold = 1000
    customer_score = 700
    
    qualified = customer_score '' special_interest_rate_threshold
    
    print('Is the customer qualified?', qualified)
    
    
    <= < >
  • A restaurant offers special menu for customers with 500mg or less sodium requirement.
    Check dish sodium content for qualification.

                    sodium_limit = 500          # Maximum sodium content allowed for the special menu
    dish_sodium_content = 350   # Sodium content of the dish
    
    qualify = dish_sodium_content '' sodium_limit
    
    print("Does the dish qualify for the special menu? ", qualify)
  • Check if the user’s subscription is active or not.

                    subscription_status = 'active'
    is_subscription_active = subscription_status '' 'active'
    
    print('Is the subscription active?', is_subscription_active)
  • Check if the currect temperature is lower than or equal the recommended storage temperature or not?

                    current_temperature = 25.0  
    recommended_temperature = 10.0
    
    is_temperature_below_recommended = current_temperature '' recommended_temperature
    
    print("Is the temperature below the recommended level?", is_temperature_below_recommended)
  • Does the company have growth compared to the previous quarter?

                    # Revenue calculation for the current quarter
    current_quarter_sales = 50000      # Total sales for the current quarter
    current_quarter_expenses = 20000   # Total expenses for the current quarter
    current_revenue = current_quarter_sales - current_quarter_expenses
    
    # Revenue calculation for the previous quarter
    previous_quarter_sales = 45000      # Total sales for the previous quarter
    previous_quarter_expenses = 18000   # Total expenses for the previous quarter
    previous_quarter_revenue = previous_quarter_sales - previous_quarter_expenses
    
    is_revenue_growth = current_revenue > previous_quarter_revenue
    
    print('Is there revenue growth compared to the previous quarter?', is_revenue_growth)
  • Has the website’s conversion rate improved compared to last month?

                    # Conversion rate calculation for the current month
    current_month_visitors = 1000      # Total number of visitors for the current month
    current_month_conversions = 50     # Total number of conversions for the current month
    current_conversion_rate = current_month_conversions / current_month_visitors
    
    # Conversion rate calculation for the previous month
    previous_month_visitors = 900    # Total number of visitors for the previous month
    previous_month_conversions = 40  # Total number of conversions for the previous month
    previous_month_conversion_rate = previous_month_conversions / previous_month_visitors
    
    is_conversion_improvement = current_conversion_rate > previous_month_conversion_rate
    
    print('Has the conversion rate improved compared to last month?', is_conversion_improvement)
  • Python Exercises for Operators

    • If you’ve faced difficulties with these exercises, take a look at Operators Module on my Python course.


    You can also share ‘Python Operators’ Exercises on your:
    X (Twitter)TelegramLinkedinFacebook – or on your favorite platform…




    Happy Coding!
    Behnam Khani