Variables

Variables are used to store data values. Use the equals sign to assign a value to a variable. Once a variable has been created it can be used in calculations. You can display the value of a variable using print().

coins = 10
coins = coins + 5
print(coins)

Output:

15

Exercises

Experiment with variables:

  1. Create variables length and width and assign them numerical values. Calculate and print the area of a rectangle using the formula: area equals length times width.

  2. Create two variables, x and y, and assign them integer values. Calculate and print their sum, difference, product, and quotient.

  3. Create a variable fahrenheit and assign it a temperature in Fahrenheit. Convert the temperature to Celsius using the formula: C=(F-32) times (5/9)

    Hint: use tab completion when typing out fahrenheit

Thanks! We hope you found what you are looking for. Please feel free to contribute via Github.