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 काउंटडाउन)!
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
shartisTrue. - While लूप — जब तक शर्त सच (
True) है, अंदर का कोड दोहराता रहता है। count -= 1- Decreases
countby 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 insertastronautinside{astronaut}. f"..."की मदद से{astronaut}की वैल्यू सीधा लाइन में छप गई।while count > 0:- Runs the indented lines repeatedly as long as
countis greater than0. - जब तक
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 दबाओ!
- Set
count = 3(or5).count = 3(या5) सेट करो। - Write
while count > 0:and print usingf"...{count}...".while count > 0:लिखो और अंदरf"...{count}..."प्रिंट करो। - Keep
count -= 1indented insidewhileso 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
- An f-string puts variables inside text:
f"Score: {points}". while condition:repeats as long as the condition isTrue.- Change the counter inside the loop (
count -= 1), or the loop never stops.
- f-string टेक्स्ट के अंदर variable रखती है:
f"Score: {points}"। while condition:तब तक दोहराता है जब तक शर्तTrueहै।- लूप के अंदर गिनती बदलो (
count -= 1), वरना लूप कभी नहीं रुकेगा।
Quick quiz
What will naam = "Ravi"; print(f"Hi {naam}") output?
naam = "Ravi" होने पर print(f"Hi {naam}") क्या आउटपुट देगा?
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
- Piggy Bank Goal (while loop + f-string)
गुल्लक का लक्ष्य (while loop + f-string)
Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.