Blog Detail

September 1, 2023

Python Variable Exercises

  • What is a variable in Python?



  • How can we describe this code?

                    color = 'blue'
  • What’s the name of this variable?

                    device = 'tablet'
  • What is the value of this variable?

                    country = 'Canada'
  • Use the name of the variable job to output its content.

                    job = 'chef'
    print('')
  • Print the value of the direction variable in the console.

                    direction = 'East'
    print("")
  • Assign dejavucode.com to the variable named website .

                    def = 'dejavucode.com'
  • Define a variable named brand and assign it Nike as its value.

                    ""
    product = "Air Max"
  • Assign the value The Legend of Zelda: Breath of the Wild to the video_game_title variable.

                    video_game_title ""
  • Update the variable to Times Square, New York .

                    event_location = 'Central Park, New York'
    event_location = ""
  • Update the variable by using the = operator.

                    favorite_color = 'Blue'
    favorite_color "" 'Red'
  • What is the output of this program?

                    size = 'Large'
    size = 'Medium'
    size = 'Small'
    
    print(size)
  • What is an argument ?



  • Pass the variable blood_type to the print function as its argument.

                    blood_type = 'O+'
    print("")
  • Find the argument in this code.

                    print('Enter your timezone!')
  • What’s wrong with this code?

                    URL = 'dejavucode.com'
    print(url)
  • What’s wrong with this code?

                    Print('Python is case-sensitive!')
  • Update the current_filter by using the default_filter .

                    default_filter = 'none'
    current_filter = 'size'
    current_filter = ""
  • Print Your feedback matters to us! in the console.

                    print("")
  • Put Hello Python! inside double quotes.

                    print(""Hello Python!")
  • What will be the output of this program?

                    total_budget = 5000 
    expenses = 2000 
    budget_remaining = total_budget - expenses
    
    print(budget_remaining)
  • Print There are 600 kilometers left to travel. in the console.

                    total_distance = 1000
    distance_traveled = 400
    distance_remaining = total_distance - distance_traveled
    
    print('')
  • Does Python run this code?

                    print('Our software is designed to simplify your life.')
  • What is the output of this program?

                    print('Happy birthday!')
    print('Welcome home')
  • What does this code displays in the console?

                    relationship_status = 'Single'
    print(relationship_status)
  • Python Exercises for Variables

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


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




    Happy Coding!
    Behnam Khani