Blog Detail

September 1, 2023

Python Operators Exercises

  • Add 10 to the number_of_items variable.

                    number_of_items = 30
    number_of_items = ''
  • Subtract 10 from the speed.

                    speed = 120
    speed = speed '' 10
    
  • Add 2000 to the marketing_budget variable using shorthand form operator .

                    marketing_budget = 10000
    marketing_budget '' 2000
  • Subtract 1.75 from the market_share variable using shorthand form operator .

                    market_share = 20
    market_share ''
  • Calculate the price you have to pay to rent a car for 7 days.

                    price = 10.40
    days = 7
    total_price = ''
    
  • What is the output of this code?

                    wallet = 500.00
    maintenance = 400.00
    
    available_money = wallet - maintenance
    
    print(available_money)
  • This program calculates the burned calories based on the steps and calories_per_step variables.
    What will be the output ?

                    steps = 1000
    calories_per_step = 0.04
    
    burned_calories = steps * calories_per_step
    
    print(burned_calories)
  • Let’s say you have sold 100 units of a product, and each unit is priced at $25.50.
    What is the output of this prgoram?

                    units_sold = 100    # Integer
    unit_price = 25.50  # Floating-point
    
    total_revenue = units_sold * unit_price
    
    print(total_revenue)
  • Imagine a customer has accumulated 500 reward points, and they earn an additional 25 points on their recent purchase.
    What will be the value of the total_points variable?

                    existing_points = 500  
    earned_points = 25  
    
    total_points = existing_points + earned_points
    
    print("Total Reward Points:", total_points)
  • Imagine you are managing a large project that involves multiple departments within your organization. The project has a total cost associated with it, and you need to allocate the cost among the departments equally.
    What will be the value of the cost_per_department variable?

                    total_cost = 50000   # Integer
    num_departments = 5  # Integer
    
    cost_per_department = total_cost / num_departments
    
    print("Cost per Department:", cost_per_department)
  • Suppose you have the number of answered customer calls and the total number of incoming calls to a call center.
    What will be the value of the response_rate_percentage variable?

                    answered_calls = 200        # Integer
    total_incoming_calls = 400  # Integer
    
    response_rate = answered_calls / total_incoming_calls
    response_rate_percentage = response_rate * 100
    
    print("Response Rate:", response_rate_percentage, "%")
  • What will be printed in the console?

                    y = 8
    z = 2
    
    print(8 / 2)
  • 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