03.16 · Python basics / Practice · 6 min
Add the values instead of joining digits
The program receives two numbers as text. It currently joins them into 72 instead of calculating their sum.
Activity 16 of 19 in Python basics
Python Basics / 03.16
Practice type conversion
Not started
Preserve two numeric text inputs and convert their values before adding them.
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Build it one step at a time
Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)4 steps · Saved work · Instant feedback
YOUR TURN
Convert the inputs before calculating the sum
Keep first_text assigned to the string "7" and second_text assigned to the string "2". Change total so it adds the integer values of both strings using int. Keep print(total). To pass: both original variables must still hold their starting strings, total must hold the number 9, and the program must print 9 exactly once. Do not replace the inputs with numeric literals. After passing, try different integer strings and predict the sum before running again.
9
Keep the starting inputs. Print these lines in this order, without extra output.
- first_text still holds the string 7
- second_text still holds the string 2
- total holds the number 9
Edit Python, then run it. Check challenge checks your output and the listed Python requirements. Your code saves on this browser after a short pause. Sign in and choose Save account draft to keep it across devices. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Need a nudge?
Look at the operand types
Both starting values are strings. With two strings, + joins text rather than adding numeric values.
Convert each value before the plus
int returns the integer represented by suitable numeric text. Apply it to each input where you calculate total, keeping the original assignments intact.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
int(first_text) and int(second_text) return numeric 7 and 2. Their sum is 9; the original variables still hold their strings. Converting after concatenating would turn "72" into 72, which is too late. Checks validate output and stored values rather than a particular syntax; vary the input strings to confirm your expressions calculate instead of hardcoding the answer.
first_text = "7"
second_text = "2"
total = int(first_text) + int(second_text)
print(total)Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in