PYTHON LESSON 7 OF 32

Decisions with if & else

An if statement chooses a path when a condition is true. else handles the other path. The colon starts a block; indent the lines inside with four spaces. == compares values, while = assigns them.

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

if शर्त सही होने पर एक रास्ता चुनता है; else दूसरा रास्ता है। कोलन के बाद ब्लॉक में चार स्पेस रखें। == तुलना और = मान रखने के लिए है।

अभ्यास: score को 40 करें और दूसरी निर्णय शाखा चलाएँ।

Hinglish mein samjhein

if condition true hone par ek raasta chunta hai, else doosra. Colon ke baad block mein 4 spaces do. == compare karta hai aur = assign karta hai.

Practice: score 40 karo aur doosri branch run karo.

A small Python example

score = 80
if score >= 60:
    print("Great work!")
else:
    print("Keep practising!")

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 score to 40 and run the other decision branch.

Check answer & explanation
score = 40
if score >= 60:
    print("Great work!")
else:
    print("Keep practising!")

40 does not satisfy score >= 60, so execution follows else and prints the encouragement message.

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

Which symbol checks equality?

  1. =
  2. ==
  3. :=
Check the quiz answer

==

== compares two values. = assigns a value.

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.