Blog Detail

September 1, 2023

Python Data Types Exercises

  • What is the output of the round() function?

                    market_share = 12.03298
    
    rounded_market_share = round(market_share, 2)
    
    print(rounded_market_share)
  • How many arguments does the round function take in the given code snippet?

                    market_share = 12.03298
    
    rounded_market_share = round(market_share, 2)
    
    print(rounded_market_share)
  • Find the lowest price.

                    product_prices = [27.99, 19.99, 23.99, 25.99, 26.99]
    
    lowest_price = ''(product_prices)
    
    print(lowest_price)
  • Find the highest temperature.

                    daily_temperatures = [25, 28, 29, 26, 30, 27]
    
    highest_temperature = ''(daily_temperatures)
    
    print(highest_temperature)
  • What is the return type of the input() function?

                    contact_number = input('Please enter your contact number:')
  • What is type casting in Python?



  • Cast the product price to a floating-point number.

                    product_price = '9.99'
    
    casted_product_price = ''(product_price)
  • Cast the image_resolution from string to integer.

                    image_resolution = '72'
    
    casted_image_resolution = ''(image_resolution)
  • What is wrong with this code?

                    message = 'You have ' + 5 + ' new messages.'
    
    print(message)
  • Debug this code.

                    message = 'You are customer number: ' + ''(1005)
  • Debug this code.

                    message = 'The product has a rating of ' + ''(4.5) + ' stars.'
  • Complete this code.

                    software_name = "SnapFood"
    current_step = 2
    total_steps = 5
    
    update_message = 'Installing ' + software_name + ': Step ' + ''(current_step) + ' of ' + str(total_steps)
    
    print(update_message)
    
  • Complete this code.

                    item_count = 5
    
    cart_message = 'You have ' + ''(item_count) + ' items in your cart.'
    
    print(cart_message)
  • Suppose you are organizing an event.
    Complete the code to determine the number of chairs needed based on the number of attendees and an additional 10 extra chairs.

                    attendees = input('How many people are attending the event? ')
    
    chairs_needed = ''(attendees) + 10
    
    print('You need ' + str(chairs_needed) + ' chairs for the event.')
  • Complete the program based on the following logic:
    Imagine you are organizing a school picnic, and you need to determine the total cost of food based on the number of students attending and the cost per meal.

    * cost_per_meal could be a floating point number

                    num_students = input('Enter the number of students attending the picnic: ')
    cost_per_meal = input('Enter the cost per meal: ')
    
    total_cost = int(num_students) * ''(cost_per_meal)
    
    print('The total cost of food for the picnic is: ' + str(total_cost))
  • Python Exercises for Data Types

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


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




    Happy Coding!
    Behnam Khani