Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMARIA Quadri
2,572 PointsHow would I make a variable that has the sum of two other variables in python?
If I want to make a variable called total and assign it the current variables, current_count and upcoming_release how would I do that?
current_count = 14
planned = 5
upcoming_releases = 2
total = 14 + 2
total = current_count + upcoming_releases
print total
del planned
2 Answers
AJ Salmon
5,675 PointsYou've got the right line in there, but you also have some extra stuff that isn't needed, which is probably messing up the answer that the challenge is looking for. Here's the code that will pass the challenge:
current_count = 14
planned = 5
upcoming_releases = 2
del planned
total = current_count + upcoming_releases
Notice how total is created after planned is deleted. It's always good to make sure that in code challenges, your new code goes below whatever code is already written (unless the challenge tells you otherwise)! But you had it right, you can add two variables together with the + symbol. Also, a side note, when you print something, make sure whatever you want printed is in parentheses directly after print, otherwise python won't understand what you're telling it to do. You don't need to print anything here, so you can delete that code. Example of proper syntax for printing:
#printing a variable
alpha = 'ABCDEF'
print(alpha)
#printing a string
print('ABCDEF')
Gerard Nwazk
Courses Plus Student 2,833 PointsHello MARIA Quadr
At first you got it wrong by assigning an integer(numbers ie: total = 14 + 2) to the variable total
Delete total = 14 + 2
finally change your print method to print(total)
so you code should look like this:
current_count = 14
upcoming_releases = 2
total = current_count + upcoming_releases
del planned
print(total)