thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

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

All courses

Python Basics / 03.16

Practice type conversion

Not started

Preserve two numeric text inputs and convert their values before adding them.

More options

Your lesson progress

Walkthrough: not startedPractice: not started

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.

Rob sees the text inputs 7 and 2, gets the incorrect joined result 72, and investigates the types used by the addition.
Rob’s comic strip · Python basics

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.

Expected output
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.

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.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

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

ONE STEP FORWARD

You preserved the original text and calculated with converted numbers. Boolean values are next in the original course order.