Content · Programming · Python

Python First Exercises: Combine Two Input Values

Combining two inputs highlights an important difference: joining text is not the same as adding numbers. Learn the essential ideas and try a practical example.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Combining two inputs highlights an important difference: joining text is not the same as adding numbers.

Understanding the Concept


When input() reads a value, it returns a string. Joining "7" and "5" produces "75", not 12. For numerical addition, convert each reply with int() or float() first. For names or words, string concatenation is appropriate. Understanding what type each input has will prevent many beginner arithmetic errors.

When and Why You Would Use This


Write a script that asks for two whole numbers. Convert both, add them, and print the result. Test with 7 and 5, then with 0 and 10. Invalid text raises ValueError; full input validation comes later.

Practical Example


first_number = int(input("First whole number: "))
second_number = int(input("Second whole number: "))
number_total = first_number + second_number
print("Sum:", number_total)

Understanding the Example


Input 7 and 5 produces Sum: 12. Without int(), two strings joined with + would produce "75". This contrast is the main lesson.

Example Output


First whole number: Second whole number: Sum: 41

Try It Yourself


First deliberately join "7" and "5" as strings. Then convert and add the values numerically.

Common Beginner Mistakes


  • Using raw input strings for arithmetic.
  • Converting data that is genuinely meant to remain text, such as names, without a reason.
  • Assuming every input is a valid integer and ignoring error messages from int().

Key Takeaways


  • All input() results start as text.
  • Use numeric conversion for calculations.
  • Choose operations based on the meaning and type of the values.
Share this resourceSend this page to someone who may find it useful.