livepython.net
CHAPTER 04Variables
4.5  PRACTICE

Python Variables Practice Questions for Beginners

Chapter 4 Recap and Practice

You can now store values, name them well and work with them. Here is the chapter in one table:

You writeIt means
name = "Sunny"store a value in a variable (name on the left)
print(name)show the value; print("name") shows the word
total = price * qtycalculate with values, store the result
user_namenames use letters, numbers and _, start with a letter
age vs Agecapital letters make a different name
class, for, if …keywords can't be names
score = score + 5a new value replaces the old one
x = y = 0one value for several variables
a, b = b, aswap two values in one line
str, int, float, booltext, whole number, decimal number, True or False
type(x)shows the type of a value

And remember: create a variable before you use it.

Practice questions

Write each program yourself. Use variables for the values, even when you could type the answer directly: that's the skill you're practising.

Python variables

  1. 16.Python Program to Create and Print a VariableEasySolve
  2. 21.Python Program to Add Two VariablesEasySolve
  3. 22.Python Program to Find the Area of a Rectangle Using VariablesMediumSolve

Naming rules

  1. 18.Python Program to Show That Variable Names Are Case-SensitiveEasySolve
  2. 33.Fix the Invalid Variable Names in a Python ProgramEasySolve

How variables work

  1. 19.Python Program to Assign One Value to Several VariablesEasySolve
  2. 20.Python Program to Reassign a VariableMediumSolve
  3. 24.Python Program to Swap Two Variables Without a Temporary VariableMediumSolve
  4. 25.Python Program to Rotate the Values of Three VariablesMediumSolve

Variable types

  1. 17.Python Program to Create and Print a Boolean VariableEasySolve
  2. 26.Python Program to Check the Type of a VariableEasySolve
  3. 34.Python Program to Print a Shopping Bill with VariablesHardSolve

Variables are the memory of your program. Next, you'll learn everything you can do with each type of value.