Calculations with variables
You've now created a savings variable, so let's start saving!
Instead of calculating with the actual values, you can use variables instead.
How much money would you have saved four months from now, if you saved $10 each month?
This is a part of the course
“Introduction to Python”
Exercise instructions
- Create a variable
monthly_savings
, equal to10
andnum_months
, equal to4
. - Multiply
monthly_savings
bynum_months
and assign it tonew_savings
. - Print the value of
new_savings
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the variables monthly_savings and num_months
# Multiply monthly_savings and num_months
new_savings = ____
# Print new_savings
This exercise is part of the course
Introduction to Python
Master the basics of data analysis with Python in just four hours. This online course will introduce the Python interface and explore popular packages.
An introduction to the basic concepts of Python. Learn how to use Python interactively and by using a script. Create your first variables and acquaint yourself with Python's basic data types.
Exercise 1: Hello Python!Exercise 2: Your first Python codeExercise 3: Python as a calculatorExercise 4: Variables and TypesExercise 5: Variable AssignmentExercise 6: Calculations with variablesExercise 7: Other variable typesExercise 8: Operations with other typesWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.