Python · Chapter 2.7 · Intermediate level

Bonus: Modern f-Strings & while Rocket Countdown

बोनस: आधुनिक f-Strings और while रॉकेट काउंटडाउन

Professional Python developers love two superpowers! First: f"..." (f-string) — put f before quotes and drop any variable directly inside {curly_braces} like f"Score: {points}". Second: while loop — whereas for runs a fixed number of times, while keeps repeating as long as a condition stays True (just like a rocket countdown until count > 0)!

प्रोफेशनल Python कोडर्स दो सुपरपावर्स रोज़ इस्तेमाल करते हैं! पहली: f"..." (f-string) — कोट्स के आगे छोटा f लगाओ और किसी भी वेरिएबल को सीधे { } के अंदर लिख दो, जैसे f"Hello {naam}"। दूसरी: while लूप — यह तब तक बार-बार चलता रहता है जब तक आपकी शर्त सच (True) रहती है (जैसे रॉकेट का 3, 2, 1 काउंटडाउन)!

In the classroom you can run and edit this code in your browser, get hints and mark the chapter as done. क्लास में यह code ब्राउज़र में चलाकर बदल सकते हो।

Words and symbols in this chapter

f"Hello {naam}"
Formatted String (f-string) — inserts variable values right inside { }.
f-string — { } के अंदर लिखे वेरिएबल की असली वैल्यू सीधा वाक्य में जोड़ देता है।
while shart:
While Loop — repeats the indented block while shart is True.
While लूप — जब तक शर्त सच (True) है, अंदर का कोड दोहराता रहता है।
count -= 1
Decreases count by 1 each turn (count = count - 1) so the loop finishes safely!
हर चक्कर में count को 1 कम करता है ताकि गिनती रुक सके (Infinite Loop न बने)!

Ready example

astronaut = "Rohan"
count = 3

print(f"Rocket Captain: {astronaut}")
while count > 0:
    print(f"T-minus {count}...")
    count -= 1

print("Liftoff! Chandrayaan Launched! 🚀")

What you will see: See memory boxes update to 0 after the countdown and inspect the clean formatted terminal output!

प्रिव्यू में जादुई मेमोरी डिब्बों के साथ पूरा रॉकेट काउंटडाउन टर्मिनल पर दिखेगा!

Line by line

print(f"Rocket Captain: {astronaut}")
Uses f"..." to smoothly insert astronaut inside {astronaut}.
f"..." की मदद से {astronaut} की वैल्यू सीधा लाइन में छप गई।
while count > 0:
Runs the indented lines repeatedly as long as count is greater than 0.
जब तक count ज़ीरो से बड़ा है, तब तक लूप चलता रहेगा।
count -= 1
Subtracts 1 on each turn (3 -> 2 -> 1 -> 0) so the countdown completes.
हर बार count में से 1 घटाता है (3 -> 2 -> 1 -> 0)।

Common mistake

✗ Wrong

print("Hi {naam}")  # forgot f!

✓ Right

print(f"Hi {naam}")

Without the letter f before quotes, {naam} prints literally instead of showing the variable's value!

कोट्स के आगे f लगाए बिना {naam} की असली वैल्यू नहीं छपेगी — f"..." ज़रूर लगाएँ!

Your task

Use an f"..." string and a while count > 0: countdown loop (remember count -= 1 inside the loop!) and run it!

f"..." स्ट्रिंग और while count > 0: लूप से काउंटडाउन चलाओ (अंदर count -= 1 ज़रूर रखो) और ▶ Run & Preview दबाओ!

  1. Set count = 3 (or 5).
    count = 3 (या 5) सेट करो।
  2. Write while count > 0: and print using f"...{count}...".
    while count > 0: लिखो और अंदर f"...{count}..." प्रिंट करो।
  3. Keep count -= 1 indented inside while so it stops cleanly!
    while के अंदर 4 स्पेस देकर count -= 1 लिखो!
Starter code for the task
hero = "Aarav"
count = 3
print("Ready", hero)

# TODO 1: while count > 0: wala loop banao (colon : ke saath)
# TODO 2: loop ke andar f-string se print karo:  print(f"Countdown: {count}")
# TODO 3: loop ke andar count -= 1 likho, warna loop kabhi nahi rukega!

print("Go! 🚀")

Do this task in the classroom: your code is checked automatically and you get hints if something is missing.

Recap

Quick quiz

What will naam = "Ravi"; print(f"Hi {naam}") output?

naam = "Ravi" होने पर print(f"Hi {naam}") क्या आउटपुट देगा?

  1. Hi {naam}
  2. Hi Ravi
  3. f Hi Ravi
  4. SyntaxError
Show the answer

Answer: B (Hi Ravi)

The f before quotes replaces {naam} with Ravi -> Hi Ravi!

f"..." स्ट्रिंग {naam} की जगह उसकी असली वैल्यू Ravi भर देती है!

Practice problems for this chapter

Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.