PYTHON LESSON 6 OF 32

Conversions & user input

input() normally asks the user for text. Convert numeric text with int() or float() before doing maths. Invalid conversions raise ValueError. In this playground, use a sample value instead of an input prompt.

हिन्दी में समझें

input() आम तौर पर उपयोगकर्ता से टेक्स्ट लेता है। गणना से पहले int() या float() से बदलें। गलत परिवर्तन पर ValueError आता है। यहाँ अभ्यास में input की जगह नमूना मान रखें।

अभ्यास: age_text को "18" करें ताकि अगला जन्मदिन 19 दिखे।

Hinglish mein samjhein

input() user se text leta hai. Maths se pehle int() ya float() se convert karo. Galat text par ValueError aata hai. Is playground mein input ki jagah sample value use karo.

Practice: age_text "18" karo. Next birthday 19 print ho.

A small Python example

age_text = "12"
age = int(age_text)
print(age + 1)

The browser playground runs real Python with Pyodide. Use sample variables instead of interactive input(). Browser package support differs from desktop Python.

Try this example in the Python playground →

Practise this idea

Change age_text to "18". The next birthday should print 19.

Check answer & explanation
age_text = "18"
age = int(age_text)
print(age + 1)

int("18") converts text to the number 18. Adding 1 then calculates 19 rather than joining two strings.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

What does int("12") return?

  1. The number 12
  2. The text "12"
  3. True
Check the quiz answer

The number 12

int() converts valid numeric text to an integer.

References & corrections

Use the official Python documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.