Coding practice problems, basic to pro
कोडिंग प्रैक्टिस सवाल: बेसिक से प्रो तक
46 problems for the four courses. Some ask you to write code, some to fix a bug, fill in blanks, predict the output or build a mini project. Read the task here, then solve it in the Practice Zone of the live classroom, where your answer is checked automatically and two hints are available.
यहाँ सवाल पढ़ो, फिर classroom के Practice Zone में हल करो — वहाँ आपका जवाब अपने-आप जाँचा जाता है और दो hints मिलते हैं।
Jump to: HTML, CSS & JavaScript, Python, C#, Machine Learning & AI.
HTML, CSS & JavaScript
Basic level
Fix the Cricket Score Page (closing tags)
This score page is broken: some boxes were opened but never closed. Find and fix the 3 mistakes so that every <h1>, <b> and <p> has its closing tag with a /.
यह स्कोर पेज टूटा हुआ है: कुछ डिब्बे खुले पर बंद नहीं हुए। 3 गलतियाँ ढूँढकर ठीक करो ताकि हर <h1>, <b> और <p> का / वाला closing tag हो।
Starter code
<h1>India vs Australia<h1>
<p>India: <b>285/4<b> in 50 overs</p>
<p>Man of the Match: <i>Virat Kohli</i>Predict: What Will the Page Show?
Read the code carefully. Which text will the browser show on the page? (Pakoda will look bold.)
कोड ध्यान से पढ़ो। ब्राउज़र पेज पर कौन-सा टेक्स्ट दिखाएगा? (Pakoda bold दिखेगा।)
<p>Chai<!-- aur samosa --> + <b>Pakoda</b> = ₹30</p>
Show the answer
Answer: A (Chai + Pakoda = ₹30)
A comment <!-- ... --> is a note for coders — the browser hides it. Tags like <b> are never shown either; they only make Pakoda bold.
Comment <!-- ... --> कोडर के लिए नोट है — ब्राउज़र उसे छुपा देता है। <b> जैसे टैग भी कभी नहीं दिखते; वे बस Pakoda को bold बनाते हैं।
Kirana Shop Signboard (h1 + p + list)
Make a web signboard for Sharma Kirana Store:
1. A big <h1> heading with the shop name.
2. A <p> paragraph with the timing, e.g. Open: 8 AM – 10 PM.
3. A <ul> list with at least 3 things the shop sells — each one inside <li>...</li>.
Sharma Kirana Store का वेब साइनबोर्ड बनाओ:
1. दुकान के नाम वाली बड़ी <h1> हेडिंग।
2. समय वाला <p> पैराग्राफ, जैसे Open: 8 AM – 10 PM।
3. एक <ul> लिस्ट जिसमें दुकान की कम से कम 3 चीज़ें हों — हर एक <li>...</li> के अंदर।
Starter code
<!-- TODO 1: <h1> mein dukaan ka naam likho -->
<!-- TODO 2: <p> mein dukaan ka time likho -->
<!-- TODO 3: <ul> ke andar 3 <li> items likho (Atta, Doodh, Biscuit...) -->Taj Mahal Photo Card (fill the attributes)
Replace every ____ with the right attribute name:
• the photo address → src
• the backup text for the photo → alt
• the link destination → href
The photo file is not on this computer, so after the fix the browser shows your alt text — that is exactly why alt matters!
हर ____ की जगह सही attribute का नाम लिखो:
• फ़ोटो का पता → src
• फ़ोटो का backup टेक्स्ट → alt
• लिंक कहाँ जाएगा → href
फ़ोटो फ़ाइल इस कंप्यूटर पर नहीं है, इसलिए ठीक करने के बाद ब्राउज़र आपका alt टेक्स्ट दिखाएगा — इसीलिए alt ज़रूरी है!
Starter code
<h2>Taj Mahal, Agra</h2>
<!-- ____ ki jagah sahi attribute likho: src, alt, href -->
<img ____="taj-mahal.jpg" ____="Taj Mahal ki safed imarat" width="220">
<p>Aur jaankari: <a ____="https://www.incredibleindia.org">Incredible India website</a></p>Intermediate level
Report Card Table
Complete Riya's report card. Under the heading row, add 3 rows (<tr>), each with 2 cells (<td>): Maths 92, Science 88, Hindi 79.
Riya का रिपोर्ट कार्ड पूरा करो। हेडिंग वाली row के नीचे 3 rows (<tr>) जोड़ो, हर row में 2 cells (<td>): Maths 92, Science 88, Hindi 79।
Starter code
<h2>📄 Report Card — Riya (Class 8)</h2>
<table border="1">
<tr>
<th>Subject</th>
<th>Marks</th>
</tr>
<!-- TODO: yahan 3 rows banao: Maths 92, Science 88, Hindi 79 -->
<!-- har row = <tr> ke andar 2 <td> -->
</table>Rail Ticket Booking Form
Build a mini train-ticket form. Inside <form> add:
1. A text box for the passenger name — type="text" with a placeholder.
2. A number box for age — type="number".
3. A drop-down <select> with 3 <option>s: Sleeper, 3AC, 2AC.
4. A Book Ticket button — <button type="submit">.
एक छोटा ट्रेन टिकट फ़ॉर्म बनाओ। <form> के अंदर जोड़ो:
1. यात्री के नाम का text box — type="text" और placeholder के साथ।
2. उम्र के लिए number box — type="number"।
3. एक drop-down <select> जिसमें 3 <option> हों: Sleeper, 3AC, 2AC।
4. Book Ticket बटन — <button type="submit">।
Starter code
<h2>🚆 Rail Ticket Booking</h2>
<form>
<!-- TODO 1: yatri ke naam ka text box (placeholder ke saath) -->
<!-- TODO 2: umar ke liye number box -->
<!-- TODO 3: <select> mein 3 option: Sleeper, 3AC, 2AC -->
<!-- TODO 4: "Book Ticket" submit button -->
</form>School Website Layout (semantic HTML5)
The school page works, but it has no structure. Wrap its parts in semantic tags — they tell Google and screen readers what each part is:
1. The school name <h1> and the menu → inside <header>.
2. The 2 menu links → inside <nav> (within the header).
3. The notice board (<h2> + <ul>) → inside <main>.
4. The © line → inside <footer>.
स्कूल का पेज चलता है, पर उसका कोई ढाँचा नहीं है। उसके हिस्सों को semantic tags में लपेटो — ये Google और screen readers को बताते हैं कि कौन-सा हिस्सा क्या है:
1. स्कूल का नाम <h1> और मेन्यू → <header> के अंदर।
2. दोनों मेन्यू लिंक → <nav> के अंदर (header के भीतर)।
3. नोटिस बोर्ड (<h2> + <ul>) → <main> के अंदर।
4. © वाली लाइन → <footer> के अंदर।
Starter code
<!-- TODO: in hisson ko semantic tags mein lapeto:
1. h1 + menu links -> <header> ... </header>
2. dono menu links -> <nav> ... </nav> (header ke andar)
3. h2 + ul (notices) -> <main> ... </main>
4. copyright wali line -> <footer> ... </footer> -->
<h1>🏫 Saraswati Vidya Mandir</h1>
<a href="#notices">Notices</a> | <a href="#contact">Contact</a>
<h2 id="notices">📢 Notice Board</h2>
<ul>
<li>Annual Sports Day: 15 December</li>
<li>PTM: Saturday, 10 AM</li>
</ul>
<p id="contact">© 2026 Saraswati Vidya Mandir, Varanasi</p>Fix the Chai Point Card (CSS bugs)
The card should be cream-orange with rounded corners, but the CSS has 3 mistakes: a missing dot . before the class name, a missing colon : and a missing semicolon ;. Fix them (keep the colours as they are).
कार्ड क्रीम-नारंगी और गोल कोनों वाला होना चाहिए, पर CSS में 3 गलतियाँ हैं: class के नाम से पहले . नहीं है, एक : छूटा है और एक ; छूटा है। इन्हें ठीक करो (रंग वैसे ही रहने दो)।
Starter code
<style>
card {
background #fff7ed;
color: #9a3412
padding: 16px;
border-radius: 12px;
}
</style>
<div class="card">
<h3>☕ Chai Point</h3>
<p>Masala Chai — ₹15 | Samosa — ₹12</p>
</div>Product Row with Flexbox (fill the blanks)
Fill the two ____ blanks so the 3 products stand side by side like on a shopping app: the row needs display: flex; and a gap with a real size such as 12px.
दोनों ____ भरो ताकि 3 प्रोडक्ट्स शॉपिंग ऐप की तरह साथ-साथ खड़े हों: row को display: flex; और 12px जैसे असली साइज़ वाला gap चाहिए।
Starter code
<style>
.row {
display: ____;
gap: ____;
justify-content: center;
}
.product {
padding: 12px;
border: 2px solid #22c55e;
border-radius: 10px;
width: 110px;
text-align: center;
}
</style>
<div class="row">
<div class="product">📱 Phone<br>₹9,999</div>
<div class="product">🎧 Earbuds<br>₹1,499</div>
<div class="product">⌚ Watch<br>₹2,199</div>
</div>Pro level
Responsive Course Cards (Grid + Media Query)
Make .courses a CSS grid with 3 equal columns (repeat(3, 1fr)) and a gap. Then add a media query so that on screens up to 600px wide it becomes 1 column. Keep the viewport <meta> line.
.courses को 3 बराबर कॉलम (repeat(3, 1fr)) और gap वाली CSS grid बनाओ। फिर एक media query जोड़ो ताकि 600px तक चौड़ी स्क्रीन पर यह 1 कॉलम बन जाए। viewport वाली <meta> लाइन रहने दो।
Starter code
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.courses {
/* TODO 1: grid banao: 3 barabar columns + gap */
}
.course { background: #e0f2fe; padding: 16px; border-radius: 10px; text-align: center; }
/* TODO 2: @media (max-width: 600px) mein .courses ko 1 column banao */
</style>
<h2>Hamare Courses</h2>
<div class="courses">
<div class="course">🌐 HTML</div>
<div class="course">🐍 Python</div>
<div class="course">🎮 C#</div>
<div class="course">🤖 AI</div>
<div class="course">📊 Excel</div>
<div class="course">🎨 Design</div>
</div>Chai Order Counter (JavaScript click)
Make the +1 Chai button work with JavaScript:
1. Create a counter let cups = 0;.
2. Listen for clicks with btn.addEventListener("click", ...).
3. On every click add 1 to cups and show it with count.textContent — e.g. Cups: 3 | Bill: ₹45 (₹15 per cup).
Then click the button in the preview!
+1 Chai बटन को JavaScript से चलाओ:
1. काउंटर बनाओ let cups = 0;।
2. btn.addEventListener("click", ...) से क्लिक सुनो।
3. हर क्लिक पर cups में 1 जोड़ो और count.textContent से दिखाओ — जैसे Cups: 3 | Bill: ₹45 (₹15 प्रति कप)।
फिर प्रिव्यू में बटन दबाओ!
Starter code
<h2>☕ Chai Order</h2>
<button id="addBtn">+1 Chai</button>
<p id="count">Cups: 0</p>
<script>
const btn = document.getElementById("addBtn");
const count = document.getElementById("count");
// TODO 1: ek counter variable banao (let) jo 0 se shuru ho
// TODO 2: btn par "click" ka event listener lagao
// TODO 3: click par counter 1 badhao aur count.textContent mein Cups + Bill dikhao
</script>Mini Project: Raju's Chai Stall Website
Build a complete one-page website for Raju's Chai Stall:
1. <header> with an <h1> and a <nav> with 2 links: href="#menu" and href="#contact".
2. <section id="menu"> with at least 3 menu cards (class="item") inside a flex row (display: flex).
3. A media query @media (max-width: 600px) that stacks the cards (e.g. flex-direction: column).
4. <section id="contact"> with an Order button that uses JavaScript (addEventListener + textContent) to show a thank-you message.
5. A <footer> with ©.
When it works, 💾 download it as index.html — you can publish it free on Netlify Drop or GitHub Pages!
Raju's Chai Stall के लिए पूरी एक-पेज वेबसाइट बनाओ:
1. <header> जिसमें <h1> और 2 लिंक वाला <nav> हो: href="#menu" और href="#contact"।
2. <section id="menu"> जिसमें flex row (display: flex) के अंदर कम से कम 3 मेन्यू कार्ड (class="item") हों।
3. एक media query @media (max-width: 600px) जो कार्ड्स को एक के नीचे एक कर दे (जैसे flex-direction: column)।
4. <section id="contact"> जिसमें Order बटन हो जो JavaScript (addEventListener + textContent) से धन्यवाद संदेश दिखाए।
5. © वाला <footer>।
चल जाए तो 💾 index.html नाम से डाउनलोड करो — Netlify Drop या GitHub Pages पर मुफ़्त में लाइव कर सकते हो!
Starter code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Raju's Chai Stall</title>
<style>
body { font-family: sans-serif; margin: 0; }
header { background: #78350f; color: white; padding: 14px; }
nav a { color: #fde68a; margin-right: 12px; }
.item { flex: 1; padding: 12px; border: 2px solid #f59e0b; border-radius: 10px; text-align: center; }
/* TODO: .menu-row ko flex row banao (gap ke saath) */
/* TODO: @media (max-width: 600px) mein .menu-row ko column banao */
</style>
</head>
<body>
<!-- TODO 1: <header> mein <h1> aur <nav> (2 links: #menu, #contact) -->
<main>
<section id="menu">
<h2>Menu</h2>
<!-- TODO 2: <div class="menu-row"> ke andar 3 <div class="item"> cards -->
</section>
<!-- TODO 3: <section id="contact"> mein Order button + <p id="msg"></p> -->
</main>
<!-- TODO 4: <footer> © ke saath -->
<!-- TODO 5: <script> mein button par click event -->
</body>
</html>Python
Basic level
Cricket Player Card (variables + print)
Make 3 variables — name (text), runs (a number) and team — and print a player card in 3 lines: Player: ..., Team: ..., Runs: .... Text needs quotes " ", numbers do not. Print the variables, don't type the values twice.
3 variables बनाओ — name (टेक्स्ट), runs (नंबर) और team — और 3 लाइनों में प्लेयर कार्ड print करो: Player: ..., Team: ..., Runs: ...। टेक्स्ट को quotes " " चाहिए, नंबर को नहीं। Variables को print करो, वैल्यू दोबारा टाइप मत करो।
Starter code
# TODO 1: name variable banao (apne favourite cricketer ka naam, quotes mein)
# TODO 2: runs variable banao (sirf number, quotes nahi)
team = "India"
print("Team:", team)
# TODO 3: Player aur Runs bhi print karoKirana Shop Bill (maths with numbers)
Riya buys 3 packets of Maggi at ₹14 each and 2 litres of milk at ₹56.5 per litre.
1. maggi_cost = maggi_price * maggi_qty and the same for milk.
2. total = maggi_cost + milk_cost.
3. Print all three, then print the bill after a 10% discount (total * 0.9).
Riya ₹14 वाले 3 Maggi पैकेट और ₹56.5 प्रति लीटर वाला 2 लीटर दूध ख़रीदती है।
1. maggi_cost = maggi_price * maggi_qty और दूध के लिए भी ऐसा ही।
2. total = maggi_cost + milk_cost।
3. तीनों print करो, फिर 10% छूट के बाद का बिल print करो (total * 0.9)।
Starter code
maggi_price = 14
maggi_qty = 3
milk_price = 56.5
milk_qty = 2
# TODO 1: maggi_cost aur milk_cost nikalo (price * qty)
# TODO 2: total = dono ka jod
# TODO 3: Maggi, Milk, Total print karo
# TODO 4: 10% discount ke baad ka bill print karo (total * 0.9)Fix the Grade Machine (if / elif / else)
This grade program has 3 mistakes: a missing colon :, a missing indentation (4 spaces) and = used instead of ==. Run it, read the red error, fix that line, and run again until it prints Grade: A for 82 marks.
इस ग्रेड प्रोग्राम में 3 गलतियाँ हैं: एक : छूटा है, एक जगह indentation (4 स्पेस) नहीं है और == की जगह = लिखा है। Run करो, लाल error पढ़ो, वह लाइन ठीक करो, और तब तक दोबारा चलाओ जब तक 82 marks पर Grade: A न छपे।
Starter code
marks = 82
if marks >= 90
print("Grade: A+")
elif marks >= 75:
print("Grade: A")
elif marks >= 33:
print("Grade: B")
else:
print("Grade: Fail")
if marks = 100:
print("Full marks!")Predict: How Many Overs?
Read the loop. What will it print? Think about where range(1, 4) stops and which line is inside the loop.
लूप पढ़ो। यह क्या print करेगा? सोचो range(1, 4) कहाँ रुकता है और कौन-सी लाइन लूप के अंदर है।
for over in range(1, 4):
print("Over", over)
print("Innings khatam!")
Show the answer
Answer: B (Over 1
Over 2
Over 3
Innings khatam!)
range(1, 4) gives 1, 2, 3 — it stops before 4. The last print has no spaces in front, so it is outside the loop and runs only once.
range(1, 4) से 1, 2, 3 मिलते हैं — 4 से पहले रुक जाता है। आख़िरी print के आगे स्पेस नहीं है, इसलिए वह लूप के बाहर है और सिर्फ़ एक बार चलता है।
Intermediate level
Train Seat Chart (list + dictionary)
The coach has passengers in a list and seat numbers in a dictionary.
1. Add "Kabir" to passengers with .append().
2. Give Kabir the seat "S4-21" in seats.
3. Print Total passengers: 4 using len().
4. Loop over seats.items() and print every name -> seat.
डिब्बे के यात्री एक list में हैं और सीट नंबर एक dictionary में।
1. .append() से passengers में "Kabir" जोड़ो।
2. seats में Kabir को सीट "S4-21" दो।
3. len() से Total passengers: 4 print करो।
4. seats.items() पर लूप चलाकर हर name -> seat print करो।
Starter code
passengers = ["Aarav", "Meera", "Rohan"]
seats = {"Aarav": "S4-12", "Meera": "S4-13", "Rohan": "S4-14"}
# TODO 1: passengers list mein "Kabir" jodo
# TODO 2: seats dictionary mein Kabir ki seat "S4-21" jodo
# TODO 3: kul yatri print karo (len)
# TODO 4: har yatri aur uski seat print karo (.items() par for loop)Tiffin Service Bill Function (fill the blanks)
A tiffin costs ₹80. For more than 10 days the price drops by ₹5 per tiffin. Fill the three ____ blanks: the keyword that creates a function, the keyword that gives back the answer, and the number of days in the last line (20).
एक टिफ़िन ₹80 का है। 10 दिन से ज़्यादा लेने पर हर टिफ़िन ₹5 सस्ता। तीनों ____ भरो: function बनाने वाला keyword, जवाब लौटाने वाला keyword, और आख़िरी लाइन में दिनों की संख्या (20)।
Starter code
# Ek tiffin Rs 80 ka hai. 10 din se zyada par Rs 5 per tiffin discount.
____ tiffin_bill(days):
price = 80
if days > 10:
price = price - 5
____ days * price
print("7 din:", tiffin_bill(7))
print("20 din:", tiffin_bill(____))Piggy Bank Goal (while loop + f-string)
Aman saves ₹150 every week for a ₹1000 cricket bat. Use a while loop that runs while savings < goal: add 150 to savings, add 1 to weeks, and print the week with an f-string like Week 1: ₹150. After the loop print Goal reached in 7 weeks! (also with an f-string).
Aman ₹1000 के क्रिकेट बैट के लिए हर हफ़्ते ₹150 बचाता है। while loop लिखो जो तब तक चले जब तक savings < goal हो: savings में 150 जोड़ो, weeks में 1 जोड़ो, और f-string से हफ़्ता print करो जैसे Week 1: ₹150। लूप के बाद Goal reached in 7 weeks! print करो (वह भी f-string से)।
Starter code
savings = 0
weeks = 0
goal = 1000
# TODO 1: while loop: jab tak savings goal se kam hai
# savings mein 150 jodo, weeks mein 1 jodo
# f-string se print karo, jaise: Week 1: ₹150
# TODO 2: loop ke baad print karo: Goal reached in 7 weeks!Predict: String Superpowers
What will this print? Remember what .strip(), .title(), len() and slicing [0:3] do.
यह क्या print करेगा? याद करो .strip(), .title(), len() और slicing [0:3] क्या करते हैं।
city = " mumbai "
city = city.strip().title()
print(city)
print(len(city))
print(city[0:3])
Show the answer
Answer: A (Mumbai
6
Mum)
.strip() removes the outside spaces and .title() makes the first letter capital → Mumbai (6 letters). city[0:3] takes positions 0, 1, 2 → Mum (the end position is not included).
.strip() बाहर के स्पेस हटाता है और .title() पहला अक्षर कैपिटल करता है → Mumbai (6 अक्षर)। city[0:3] जगह 0, 1, 2 लेता है → Mum (आख़िरी जगह शामिल नहीं होती)।
Pro level
Safe ATM Withdrawal (input + try / except / raise / finally)
Make the ATM program crash-proof:
1. Put the risky code inside try:.
2. If amount > balance, raise ValueError("Balance kam hai!").
3. except ValueError as e: → print Transaction cancel: and the reason e.
4. finally: → print Card wapas lo 💳 (always).
Try the 📥 Input values abc, 2000 and 9000 — the program must never crash.
ATM प्रोग्राम को crash-proof बनाओ:
1. जोखिम वाला कोड try: के अंदर रखो।
2. अगर amount > balance हो तो raise ValueError("Balance kam hai!")।
3. except ValueError as e: → Transaction cancel: और कारण e print करो।
4. finally: → Card wapas lo 💳 print करो (हमेशा)।
📥 Input में abc, 2000 और 9000 आज़माओ — प्रोग्राम कभी crash नहीं होना चाहिए।
Starter code
balance = 5000
text = input("Kitne paise nikalne hain? ")
# TODO 1: neeche ki 3 lines ko try: ke andar daalo (4 spaces aage)
amount = int(text)
# TODO 2: agar amount balance se zyada ho to ValueError raise karo: "Balance kam hai!"
balance = balance - amount
print(f"₹{amount} nikale. Bacha: ₹{balance}")
# TODO 3: except ValueError as e: -> "Transaction cancel:" aur e print karo
# TODO 4: finally: -> "Card wapas lo 💳" print karoFix the UPI Wallet Class
This Wallet class crashes. It has 2 classic OOP bugs: a method without self, and text + number joined with +. Fix both so the output is:Paid ₹120. Bacha: ₹380 and then Balance kam hai!.
यह Wallet class crash होती है। इसमें 2 मशहूर OOP गलतियाँ हैं: बिना self वाला method, और + से टेक्स्ट + नंबर जोड़ना। दोनों ठीक करो ताकि आउटपुट हो:Paid ₹120. Bacha: ₹380 और फिर Balance kam hai!।
Starter code
class Wallet:
def __init__(self, owner, balance):
self.owner = owner
self.balance = balance
def pay(amount):
if amount > self.balance:
print("Balance kam hai!")
else:
self.balance = self.balance - amount
print("Paid ₹" + amount + ". Bacha: ₹" + self.balance)
w = Wallet("Aman", 500)
w.pay(120)
w.pay(1000)Mini Project: Class Result Manager
Build a school result system for 5 students stored as a list of dictionaries:
1. A function grade(marks) that returns A+ (90+), A (75+), B (60+), C (33+) or Fail.
2. A ranked report, topper first, using sorted(..., key=lambda s: s["marks"], reverse=True) and enumerate, in the format 1. Ananya - 95 - A+.
3. A list comprehension with the names of students who failed.
4. The class average rounded to 1 decimal with round(average, 1).
5 छात्रों का स्कूल रिज़ल्ट सिस्टम बनाओ, डेटा dictionaries की list में है:
1. Function grade(marks) जो A+ (90+), A (75+), B (60+), C (33+) या Fail लौटाए।
2. रैंक वाली रिपोर्ट, टॉपर सबसे ऊपर — sorted(..., key=lambda s: s["marks"], reverse=True) और enumerate से, ऐसे: 1. Ananya - 95 - A+।
3. फ़ेल हुए छात्रों के नामों की list comprehension।
4. round(average, 1) से 1 दशमलव तक क्लास का औसत।
Starter code
students = [
{"name": "Ananya", "marks": 95},
{"name": "Kabir", "marks": 72},
{"name": "Isha", "marks": 88},
{"name": "Dev", "marks": 28},
{"name": "Meera", "marks": 64},
]
def grade(marks):
# TODO 1: 90+ -> "A+", 75+ -> "A", 60+ -> "B", 33+ -> "C", warna "Fail"
return "?"
# TODO 2: marks ke hisaab se sort karo (topper pehle) aur rank ke saath print karo
# TODO 3: fail hone walon ke naam list comprehension se nikalo aur print karo
# TODO 4: class ka average nikalo aur round(..., 1) karke print karoC#
Basic level
Fix the Game Loading Screen (3 compile errors)
The compiler refuses to run this program. Fix the 3 mistakes one by one (Run after each fix and read the new error):
1. console must be Console (capital C).
2. Writeline must be WriteLine (capital L).
3. A ; is missing at the end of a line.
Compiler यह प्रोग्राम चलाने से मना कर रहा है। 3 गलतियाँ एक-एक करके ठीक करो (हर बार Run करो और नई error पढ़ो):
1. console को Console (बड़ा C) करो।
2. Writeline को WriteLine (बड़ा L) करो।
3. एक लाइन के आख़िर में ; छूटा है।
Starter code
using System;
class Program {
static void Main() {
console.WriteLine("Namaste Gamers!");
Console.Writeline("Game loading...");
Console.WriteLine("Level 1 start!")
}
}Game Hero Profile (data types)
Create your hero Veer with the right C# data types and print each value:
• int health = 100;
• string weapon = "Trishul";
• double speed = 7.5;
• bool hasShield = true;coins is already done — copy its style. Text needs " ", every line ends with ;.
अपने हीरो Veer को सही C# data types के साथ बनाओ और हर वैल्यू print करो:
• int health = 100;
• string weapon = "Trishul";
• double speed = 7.5;
• bool hasShield = true;coins पहले से बना है — उसी तरह लिखो। टेक्स्ट को " " चाहिए, हर लाइन ; से ख़त्म होती है।
Starter code
using System;
class Program {
static void Main() {
int coins = 750;
// TODO 1: int health = 100;
// TODO 2: string weapon = "Trishul";
// TODO 3: double speed = 7.5;
// TODO 4: bool hasShield = true;
Console.WriteLine("Coins: " + coins);
// TODO 5: Health, Weapon, Speed aur Shield bhi print karo
}
}Railway Ticket Fare (if / else if / else)
Full fare is ₹500. Write if / else if / else so that:
• age < 12 → Child ticket: ₹250 (half: fare / 2)
• age >= 60 → Senior ticket: ₹300 (fare - 200)
• everyone else → Full ticket: ₹500
The checker also tries ages 8 and 30, so all three branches must work. Keep the line int age = 65;.
पूरा किराया ₹500 है। if / else if / else ऐसे लिखो:
• age < 12 → Child ticket: ₹250 (आधा: fare / 2)
• age >= 60 → Senior ticket: ₹300 (fare - 200)
• बाकी सब → Full ticket: ₹500
Checker उम्र 8 और 30 भी आज़माएगा, इसलिए तीनों रास्ते सही चलने चाहिए। int age = 65; वाली लाइन रहने दो।
Starter code
using System;
class Program {
static void Main() {
int age = 65;
int fare = 500;
// TODO: if / else if / else likho
// age < 12 -> "Child ticket: ₹" + fare / 2
// age >= 60 -> "Senior ticket: ₹" + (fare - 200)
// baaki sab -> "Full ticket: ₹" + fare
}
}Predict: Enemy Waves (for loop + int division)
What will this C# program print? Look at the loop limits and remember that int / int drops the decimal part.
यह C# प्रोग्राम क्या print करेगा? लूप की सीमा देखो और याद रखो कि int / int दशमलव वाला हिस्सा हटा देता है।
using System;
class Program {
static void Main() {
for (int i = 1; i <= 3; i++) {
Console.WriteLine("Wave " + i + ": " + (100 / i) + " HP");
}
}
}
Show the answer
Answer: A (Wave 1: 100 HP
Wave 2: 50 HP
Wave 3: 33 HP)
i goes 1, 2, 3 (i <= 3 includes 3). 100 / 3 with two ints is 33 — C# throws away the decimal part. Use 100.0 / i if you want decimals.
i 1, 2, 3 चलता है (i <= 3 में 3 भी शामिल)। दो int वाला 100 / 3 = 33 — C# दशमलव हिस्सा फेंक देता है। दशमलव चाहिए तो 100.0 / i लिखो।
Intermediate level
Combo Buttons (static void methods)
In a game every button runs a method. Inside class Program write:
• static void Jump() → prints Jump!
• static void Attack() → prints Sword Slash! -20 HP
• static void Heal(int amount) → prints Healed +25 HP for Heal(25)
Then in Main play the combo Jump, Attack, Attack, Heal(25) — and watch the hero in the preview!
गेम में हर बटन एक method चलाता है। class Program के अंदर लिखो:
• static void Jump() → Jump! print करे
• static void Attack() → Sword Slash! -20 HP print करे
• static void Heal(int amount) → Heal(25) पर Healed +25 HP print करे
फिर Main में कॉम्बो चलाओ Jump, Attack, Attack, Heal(25) — और प्रिव्यू में हीरो को देखो!
Starter code
using System;
class Program {
// TODO 1: static void Jump() -> "Jump!" print kare
// TODO 2: static void Attack() -> "Sword Slash! -20 HP" print kare
// TODO 3: static void Heal(int amount) -> "Healed +" + amount + " HP" print kare
static void Main() {
// TODO 4: combo chalao: Jump, Attack, Attack, Heal(25)
}
}IPL Player Cards (class & object — fill the blanks)
Fill the three ____ blanks:
1. The keyword that creates a real object from the class (new).
2. The method that prints the card (ShowCard).
3. The field that stores the player's name (name).
तीनों ____ भरो:
1. Class से असली object बनाने वाला keyword (new)।
2. कार्ड print करने वाला method (ShowCard)।
3. खिलाड़ी का नाम रखने वाला field (name)।
Starter code
using System;
class Player {
public string name;
public int runs;
public void ShowCard() {
Console.WriteLine(name + " ne " + runs + " runs banaye!");
}
}
class Program {
static void Main() {
Player p1 = ____ Player();
p1.name = "Rohit";
p1.runs = 64;
p1.____();
Player p2 = new Player();
p2.____ = "Shubman";
p2.runs = 91;
p2.ShowCard();
}
}Predict: The Hero's Backpack (array + foreach)
What does this program print? Remember: array positions start at 0, bag.Length counts the slots, and foreach visits every item.
यह प्रोग्राम क्या print करेगा? याद रखो: array की जगहें 0 से शुरू होती हैं, bag.Length खाने गिनता है, और foreach हर चीज़ पर जाता है।
using System;
class Program {
static void Main() {
string[] bag = { "Sword", "Potion", "Shield", "Potion" };
int potions = 0;
foreach (string item in bag) {
if (item == "Potion") {
potions++;
}
}
bag[0] = "Golden Sword";
Console.WriteLine(bag.Length + " items, " + potions + " potions, first: " + bag[0]);
}
}
Show the answer
Answer: A (4 items, 2 potions, first: Golden Sword)
bag.Length is 4 (positions 0, 1, 2, 3). The loop finds "Potion" twice. bag[0] is the first slot, and it was changed to "Golden Sword" before the print line runs.
bag.Length = 4 (जगहें 0, 1, 2, 3)। लूप को "Potion" दो बार मिलता है। bag[0] पहला खाना है, और print वाली लाइन से पहले ही उसे "Golden Sword" कर दिया गया था।
Electricity Bill Method (return + ReadLine)
Electricity costs ₹5 per unit for the first 100 units and ₹8 per unit above 100. Write a method static int Bill(int units) that returns the amount, call it from Main with the units typed in the 📥 Input box, and print Bill: ₹....
150 units → 100 × 5 + 50 × 8 = ₹900. The checker also tries 80 units (→ ₹400).
बिजली पहले 100 units तक ₹5 प्रति unit और 100 के ऊपर ₹8 प्रति unit है। Method static int Bill(int units) लिखो जो रक़म return करे, Main से 📥 Input box में लिखे units के साथ उसे बुलाओ और Bill: ₹... print करो।
150 units → 100 × 5 + 50 × 8 = ₹900। Checker 80 units (→ ₹400) भी आज़माएगा।
Starter code
using System;
class Program {
// TODO 1: static int Bill(int units) method banao
// 100 tak: units * 5
// 100 ke upar: 100 * 5 + (units - 100) * 8
// jawab return karo
static void Main() {
Console.Write("Units? ");
int units = int.Parse(Console.ReadLine());
// TODO 2: Bill(units) call karo aur "Bill: ₹..." print karo
}
}Game Shop (List<T> + while + break)
You have 500 coins. Go through the shop items in order with a while (i < shop.Count) loop:
• If prices[i] > coins → print Not enough coins for Bow (the item name) and break.
• Otherwise subtract the price, inventory.Add(shop[i]), print Bought Sword, coins left: 300, and i++.
After the loop print Inventory: Sword, Shield, Potion (3 items) using string.Join(", ", inventory) and inventory.Count.
आपके पास 500 coins हैं। while (i < shop.Count) लूप से दुकान की चीज़ें क्रम से देखो:
• अगर prices[i] > coins → Not enough coins for Bow (चीज़ का नाम) print करो और break।
• वरना दाम घटाओ, inventory.Add(shop[i]), Bought Sword, coins left: 300 print करो, और i++।
लूप के बाद string.Join(", ", inventory) और inventory.Count से Inventory: Sword, Shield, Potion (3 items) print करो।
Starter code
using System;
using System.Collections.Generic;
class Program {
static void Main() {
int coins = 500;
List<string> shop = new List<string> { "Sword", "Shield", "Potion", "Bow" };
List<int> prices = new List<int> { 200, 150, 50, 300 };
List<string> inventory = new List<string>();
int i = 0;
// TODO 1: while (i < shop.Count) loop likho
// TODO 2: agar prices[i] > coins -> "Not enough coins for " + shop[i] print karo aur break
// TODO 3: warna coins ghatao, inventory.Add(shop[i]), "Bought ..." print karo, i++
// TODO 4: loop ke baad inventory aur uska Count print karo
}
}Pro level
Fix the Bank Account (encapsulation bugs)
This BankAccount keeps balance private (good!) but has 2 bugs:
1. Main reads the private field acc.balance → compile error CS0122. Use the public property Balance instead (do not make the field public).
2. The constructor writes balance = balance; — this copies the parameter into itself, so the account starts with ₹0. Use this.balance = balance;.
After fixing: Withdraw 2000: False and Priya ka balance: ₹1500.
यह BankAccount balance को private रखता है (अच्छी बात!) पर इसमें 2 गलतियाँ हैं:
1. Main private field acc.balance पढ़ता है → compile error CS0122। उसकी जगह public property Balance लगाओ (field को public मत करो)।
2. Constructor में balance = balance; लिखा है — यह parameter को उसी में कॉपी करता है, इसलिए अकाउंट ₹0 से शुरू होता है। this.balance = balance; लिखो।
ठीक करने के बाद: Withdraw 2000: False और Priya ka balance: ₹1500।
Starter code
using System;
class BankAccount {
private int balance;
public string Owner { get; private set; }
public int Balance {
get { return balance; }
}
public BankAccount(string owner, int balance) {
Owner = owner;
balance = balance;
}
public void Deposit(int amount) {
if (amount > 0) {
balance += amount;
}
}
public bool Withdraw(int amount) {
if (amount <= 0 || amount > balance) {
return false;
}
balance -= amount;
return true;
}
}
class Program {
static void Main() {
BankAccount acc = new BankAccount("Priya", 1000);
acc.Deposit(500);
bool ok = acc.Withdraw(2000);
Console.WriteLine("Withdraw 2000: " + ok);
Console.WriteLine(acc.Owner + " ka balance: ₹" + acc.balance);
}
}Boss Battle (inheritance + override)
class Enemy is ready. Create class Boss : Enemy:
1. A constructor public Boss(string name) : base(name, 500) { } — every boss starts with 500 HP.
2. public override void Attack() that prints Ravan uses FIRE BREATH for 50 damage! (use Name).
3. In Main, add new Boss("Ravan") to the enemies list.
The same foreach loop then calls the right Attack() for each enemy — that is polymorphism.
class Enemy तैयार है। class Boss : Enemy बनाओ:
1. Constructor public Boss(string name) : base(name, 500) { } — हर बॉस 500 HP से शुरू होता है।
2. public override void Attack() जो Ravan uses FIRE BREATH for 50 damage! print करे (Name लगाओ)।
3. Main में enemies list में new Boss("Ravan") जोड़ो।
फिर वही foreach लूप हर दुश्मन का सही Attack() चलाएगा — इसे polymorphism कहते हैं।
Starter code
using System;
using System.Collections.Generic;
class Enemy {
public string Name;
public int Health;
public Enemy(string name, int health) {
Name = name;
Health = health;
}
public virtual void Attack() {
Console.WriteLine(Name + " attacks for 10 damage");
}
}
// TODO 1: class Boss : Enemy banao
// constructor: public Boss(string name) : base(name, 500) { }
// public override void Attack() -> Name + " uses FIRE BREATH for 50 damage!"
class Program {
static void Main() {
List<Enemy> enemies = new List<Enemy>();
enemies.Add(new Enemy("Goblin", 50));
enemies.Add(new Enemy("Wolf", 80));
// TODO 2: enemies.Add(new Boss("Ravan"));
foreach (Enemy e in enemies) {
Console.Write(e.Name + " (HP " + e.Health + "): ");
e.Attack();
}
}
}Mini Project: Arjun vs Mahishasura RPG Battle
Build a turn-based battle that uses everything from the C# course:
1. enum Move { Attack, Heal, Special }.
2. class Fighter with Name, Health, a constructor and bool IsAlive() (returns Health > 0).
3. Random rng = new Random(7); (a fixed seed gives the same battle every run).
4. A while loop that runs while both fighters are alive (max 20 rounds). Each round pick a move with (Move)rng.Next(0, 3) and use a switch: Attack = 10–20 damage (rng.Next(10, 21)), Heal = hero +15 HP, Special = 30 damage. If the boss is still alive it hits back for rng.Next(5, 16).
5. Add one line per round to a List<string> log in the form Round <number>: <move> | Boss HP <hp> | Hero HP <hp>, print the log with foreach, then Winner: ....
ऐसी turn-based लड़ाई बनाओ जिसमें C# कोर्स की हर चीज़ लगे:
1. enum Move { Attack, Heal, Special }।
2. class Fighter जिसमें Name, Health, एक constructor और bool IsAlive() (Health > 0 लौटाए) हो।
3. Random rng = new Random(7); (fixed seed से हर बार वही लड़ाई)।
4. while लूप जो दोनों ज़िंदा रहने तक चले (ज़्यादा से ज़्यादा 20 round)। हर round (Move)rng.Next(0, 3) से move चुनो और switch लगाओ: Attack = 10–20 damage (rng.Next(10, 21)), Heal = हीरो +15 HP, Special = 30 damage। अगर boss ज़िंदा है तो वह rng.Next(5, 16) का वार करता है।
5. हर round की एक लाइन List<string> log में इस रूप में जोड़ो: Round <number>: <move> | Boss HP <hp> | Hero HP <hp>, foreach से log print करो, फिर Winner: ...।
Starter code
using System;
using System.Collections.Generic;
// TODO 1: enum Move { Attack, Heal, Special }
class Fighter {
public string Name;
public int Health;
// TODO 2: constructor Fighter(string name, int health)
// TODO 3: public bool IsAlive() -> Health > 0
}
class Program {
static void Main() {
// TODO 4: Random rng = new Random(7);
// TODO 5: Fighter hero = new Fighter("Arjun", 100); Fighter boss = new Fighter("Mahishasura", 120);
List<string> log = new List<string>();
int round = 1;
// TODO 6: while (hero.IsAlive() && boss.IsAlive() && round <= 20) { ... switch (move) { ... } ... }
foreach (string line in log) {
Console.WriteLine(line);
}
// TODO 7: Winner print karo
}
}Machine Learning & AI
Basic level
Your First "Model": Predict Tomorrow's Chai Sales
Raju counted the cups of chai he sold in the last 7 days. The simplest prediction for tomorrow is the average of the past days — that is already a tiny "model" that learns from data!
1. total = sum(sales)
2. days = len(sales)
3. prediction = total / days
4. Print Total cups: 364 and Kal ki prediction: 52.0 cups.
Raju ने पिछले 7 दिनों में बिके चाय के कप गिने। कल का सबसे आसान अंदाज़ा है पिछले दिनों का औसत — यह भी डेटा से सीखने वाला एक छोटा "model" है!
1. total = sum(sales)
2. days = len(sales)
3. prediction = total / days
4. Total cups: 364 और Kal ki prediction: 52.0 cups print करो।
Starter code
# Pichhle 7 din mein chai ke kitne cup bike
sales = [40, 52, 47, 60, 55, 49, 61]
# TODO 1: total = sum(sales)
# TODO 2: days = len(sales)
# TODO 3: prediction = total / days
# TODO 4: Total aur prediction print karoLemon or Coconut? Train Your First AI
X_weight has fruit weights in grams (the features / clues) and y_fruit has the answers (the labels).
1. Train the lab's built-in helper model with model.fit(X_weight, y_fruit).
2. Print the prediction for a 75 g fruit as 75g: Lemon.
3. Print the prediction for a 1300 g fruit as 1300g: Coconut.
X_weight में फलों का वज़न (ग्राम में) है (features / सुराग) और y_fruit में जवाब (labels)।
1. लैब के built-in helper model को model.fit(X_weight, y_fruit) से सिखाओ।
2. 75 g वाले फल का अंदाज़ा 75g: Lemon की तरह print करो।
3. 1300 g वाले फल का अंदाज़ा 1300g: Coconut की तरह print करो।
Starter code
# Wazan (grams) -> Phal
X_weight = [60, 70, 80, 1200, 1400, 1500]
y_fruit = ["Lemon", "Lemon", "Lemon", "Coconut", "Coconut", "Coconut"]
# TODO 1: model.fit(X_weight, y_fruit) se AI ko sikhao
# TODO 2: print("75g:", model.predict(75))
# TODO 3: 1300 gram wale phal ki prediction print karoFix the Marks Predictor (Linear Regression)
This study-hours → marks predictor has 2 classic ML bugs:
1. It calls predict before fit (asking the exam before teaching).
2. hours has 5 examples but marks has only 4 — every example needs an answer. The missing mark for 5 hours is 75.
Fix both. The model should then predict 85.0 marks for 6 hours. (Real scikit-learn wants each example as a row: [[1], [2], ...]; round(..., 1) keeps 1 decimal.)
इस पढ़ाई के घंटे → marks प्रेडिक्टर में 2 मशहूर ML गलतियाँ हैं:
1. यह fit से पहले predict बुलाता है (पढ़ाने से पहले exam)।
2. hours में 5 उदाहरण हैं पर marks में सिर्फ़ 4 — हर उदाहरण का जवाब चाहिए। 5 घंटे वाले के marks 75 हैं।
दोनों ठीक करो। फिर model 6 घंटे के लिए 85.0 marks बताएगा। (असली scikit-learn हर उदाहरण को row की तरह चाहता है: [[1], [2], ...]; round(..., 1) 1 दशमलव तक रखता है।)
Starter code
from sklearn.linear_model import LinearRegression
# Padhai ke ghante -> Exam marks
hours = [[1], [2], [3], [4], [5]]
marks = [35, 45, 55, 65]
model = LinearRegression()
print("6 ghante padhai -> marks:", round(model.predict([[6]])[0], 1))
model.fit(hours, marks)Predict: The Monsoon Decision Tree
A trained decision tree is just a set of if-questions. Follow the questions for each day — what will be printed?
सीखा हुआ decision tree बस if-सवालों का सेट है। हर दिन के लिए सवालों के रास्ते पर चलो — क्या print होगा?
def mausam(humidity, clouds):
if humidity > 70:
if clouds == "kaale":
return "Baarish"
return "Shayad"
return "Dhoop"
print(mausam(85, "kaale"))
print(mausam(85, "safed"))
print(mausam(40, "kaale"))
Show the answer
Answer: A (Baarish
Shayad
Dhoop)
Day 1: humidity 85 > 70 and dark clouds → Baarish. Day 2: 85 > 70 but white clouds → Shayad. Day 3: 40 is not > 70, so the tree stops at the first question → Dhoop (the clouds are never checked).
दिन 1: humidity 85 > 70 और काले बादल → Baarish। दिन 2: 85 > 70 पर सफ़ेद बादल → Shayad। दिन 3: 40, 70 से बड़ा नहीं, इसलिए tree पहले सवाल पर ही रुक जाता है → Dhoop (बादल देखे ही नहीं जाते)।
Intermediate level
Chai or Lassi? KNN Neighbours (fill the blanks)
A tea stall predicts what customers want from the weather: [temperature °C, humidity %]. Fill the three ____ blanks: look at the 3 nearest neighbours, train the model, and ask it about a hot day [39, 33].
एक चाय की दुकान मौसम से अंदाज़ा लगाती है कि ग्राहक क्या लेंगे: [तापमान °C, humidity %]। तीनों ____ भरो: 3 सबसे पास के पड़ोसी देखो, model को सिखाओ, और गर्म दिन [39, 33] के बारे में पूछो।
Starter code
from sklearn.neighbors import KNeighborsClassifier
# [taapmaan °C, humidity %] -> log kya peete hain
X = [[42, 30], [40, 35], [38, 40], [15, 70], [12, 80], [18, 75]]
y = ["Lassi", "Lassi", "Lassi", "Chai", "Chai", "Chai"]
knn = KNeighborsClassifier(n_neighbors=____)
knn.____(X, y)
print("Garmi [39, 33]:", knn.____([[39, 33]])[0])
print("Sardi [14, 72]:", knn.predict([[14, 72]])[0])Food App Review Mood Detector (NLP)
Teach the lab's built-in text helper nlp_model with 6 food-delivery reviews, then predict the mood of 2 new reviews:
1. nlp_model.fit(reviews, moods)
2. Print Review 1: + the mood of "Biryani bahut tasty aur garam".
3. Print Review 2: + the mood of "Khana late aur thanda".
लैब के built-in टेक्स्ट helper nlp_model को 6 फ़ूड-डिलीवरी रिव्यू से सिखाओ, फिर 2 नए रिव्यू का मूड बताओ:
1. nlp_model.fit(reviews, moods)
2. Review 1: + "Biryani bahut tasty aur garam" का मूड print करो।
3. Review 2: + "Khana late aur thanda" का मूड print करो।
Starter code
# Food delivery app ke reviews -> mood
reviews = [
"Khana bahut tasty tha",
"Delivery fast aur garam khana",
"Paneer ekdum mast tha",
"Khana thanda aur bekaar",
"Delivery late aur ganda packing",
"Bilkul bakwas taste",
]
moods = ["Positive 😊", "Positive 😊", "Positive 😊", "Negative 😡", "Negative 😡", "Negative 😡"]
# TODO 1: nlp_model.fit(reviews, moods)
# TODO 2: "Biryani bahut tasty aur garam" ka mood print karo (Review 1:)
# TODO 3: "Khana late aur thanda" ka mood print karo (Review 2:)Predict: One Neuron Decides
A neural network is made of tiny neurons. Each one multiplies its inputs by weights, adds them up, adds a bias and "fires" if the total is above 0. What does this neuron print?
Neural network छोटे-छोटे neurons से बनता है। हर neuron अपने inputs को weights से गुणा करता है, सब जोड़ता है, bias जोड़ता है और कुल 0 से ज़्यादा हो तो "fire" करता है। यह neuron क्या print करेगा?
inputs = [1, 0, 1]
weights = [0.5, 0.9, 0.2]
bias = -0.6
total = 0
for x, w in zip(inputs, weights):
total = total + x * w
total = total + bias
print(round(total, 2))
print("Neuron fires!" if total > 0 else "Neuron sleeps")
Show the answer
Answer: A (0.1
Neuron fires!)
1×0.5 + 0×0.9 + 1×0.2 = 0.7 (the middle input is 0, so its weight 0.9 does not count). Then 0.7 + (−0.6) = 0.1, which is above 0 → the neuron fires. Training a network = adjusting these weights and biases again and again (epochs).
1×0.5 + 0×0.9 + 1×0.2 = 0.7 (बीच वाला input 0 है, इसलिए उसका weight 0.9 नहीं जुड़ता)। फिर 0.7 + (−0.6) = 0.1, जो 0 से ज़्यादा है → neuron fire करता है। Network को train करना = इन weights और bias को बार-बार (epochs) ठीक करना।
Master Prompt: Board Exam Study Plan
The prompt "exam plan" is too vague. Write a master prompt = Role + clear Task + Output format:
1. role — who should the AI act as? e.g. "Experienced Board Exam Mentor".
2. prompt — a clear task (at least 18 characters), e.g. which class, subject and how many days.
3. style — the output format, e.g. "Hinglish mein 7 bullet points, har din ka ek example".
4. answer = ai_assistant.ask(prompt, role, style) and print it. Aim for a 100/100 prompt score!
प्रॉम्प्ट "exam plan" बहुत अधूरा है। मास्टर प्रॉम्प्ट लिखो = Role + साफ़ काम + Output format:
1. role — AI किसकी तरह जवाब दे? जैसे "Experienced Board Exam Mentor"।
2. prompt — साफ़ काम (कम से कम 18 अक्षर), जैसे कौन-सी क्लास, विषय और कितने दिन।
3. style — जवाब का format, जैसे "Hinglish mein 7 bullet points, har din ka ek example"।
4. answer = ai_assistant.ask(prompt, role, style) और print करो। 100/100 प्रॉम्प्ट स्कोर का लक्ष्य रखो!
Starter code
# Board exam ke liye study plan chahiye — par yeh prompt bahut kamzor hai!
prompt = "exam plan"
# TODO 1: role = "..." (AI kaun banega?)
# TODO 2: prompt ko saaf aur poora likho (class, subject, kitne din)
# TODO 3: style = "..." (format: bullet points / steps / table, Hinglish)
# TODO 4: answer = ai_assistant.ask(prompt, role, style)
answer = ai_assistant.ask(prompt)
print(answer)Pro level
Pass or Fail? Train/Test Split + Accuracy
Build an honest model with real scikit-learn code:
1. Import train_test_split, KNeighborsClassifier and accuracy_score.
2. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42) and print Train: 9 | Test: 3.
3. model = KNeighborsClassifier(n_neighbors=3) and fit it only on X_train, y_train.
4. Predict X_test and print Accuracy: with accuracy_score(y_test, predictions).
असली scikit-learn कोड से एक ईमानदार model बनाओ:
1. train_test_split, KNeighborsClassifier और accuracy_score import करो।
2. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42) और Train: 9 | Test: 3 print करो।
3. model = KNeighborsClassifier(n_neighbors=3) और उसे सिर्फ़ X_train, y_train पर fit करो।
4. X_test पर predict करो और accuracy_score(y_test, predictions) से Accuracy: print करो।
Starter code
# [roz padhai ke ghante, attendance %] -> result
X = [[6, 90], [7, 85], [8, 95], [5, 80], [9, 92], [6, 88],
[1, 40], [2, 35], [0, 50], [1, 45], [2, 30], [3, 42]]
y = ["Pass", "Pass", "Pass", "Pass", "Pass", "Pass",
"Fail", "Fail", "Fail", "Fail", "Fail", "Fail"]
# TODO 1: train_test_split, KNeighborsClassifier aur accuracy_score import karo
# TODO 2: data ko 75% train / 25% test mein baanto (random_state=42) aur sizes print karo
# TODO 3: model ko SIRF X_train, y_train par fit karo
# TODO 4: X_test par predict karo aur accuracy print karoFix the Data Cleaning + Min-Max Scaling
Gym members' heights have missing values (None). The code removes them into clean, then scales every height to 0 … 1 with min-max scaling: (h - smallest) / (largest - smallest). It has 2 bugs:
1. min / max are taken from the dirty list heights (with None) → TypeError.
2. The formula is missing brackets, so Python divides first.
Fix both. Correct result: Scaled: [0.0, 0.5, 0.73, 0.27, 1.0].
जिम मेंबर्स की height में कुछ वैल्यू गायब (None) हैं। कोड उन्हें हटाकर clean बनाता है, फिर min-max scaling से हर height को 0 … 1 में बदलता है: (h - smallest) / (largest - smallest)। इसमें 2 गलतियाँ हैं:
1. min / max गंदी list heights (जिसमें None है) से लिए गए → TypeError।
2. फ़ॉर्मूले में ब्रैकेट नहीं हैं, इसलिए Python पहले भाग करता है।
दोनों ठीक करो। सही नतीजा: Scaled: [0.0, 0.5, 0.73, 0.27, 1.0]।
Starter code
# Gym members ki height (cm) — kuch entries missing (None) hain
heights = [150, 165, None, 172, 158, None, 180]
clean = [h for h in heights if h is not None]
print("Clean data:", clean)
smallest = min(heights)
largest = max(heights)
scaled = []
for h in clean:
scaled.append(round(h - smallest / (largest - smallest), 2))
print("Scaled:", scaled)Mini Project: SMS Spam Detector from Scratch (+ Responsible AI)
Build a complete spam filter without any library — the same idea real filters started with:
1. clean(text) → lowercase, remove !?., and return the list of words (.split()).
2. Train: for every message in train, count its words in spam_words or ham_words (dictionaries): spam_words[w] = spam_words.get(w, 0) + 1.
3. predict(text) → score = spam counts − ham counts of its words; score > 0 → "spam", score < 0 → "ham", otherwise "unsure".
4. Test on the 4 unseen messages, print each guess, count the correct ones and print Accuracy: 1.0.
5. Responsible AI: an "unsure" message must not be deleted automatically — a human should check it.
बिना किसी library के पूरा spam filter बनाओ — असली filters भी इसी विचार से शुरू हुए थे:
1. clean(text) → lowercase करो, !?., हटाओ और शब्दों की list लौटाओ (.split())।
2. Train: train के हर संदेश के शब्द spam_words या ham_words (dictionaries) में गिनो: spam_words[w] = spam_words.get(w, 0) + 1।
3. predict(text) → score = शब्दों की spam गिनती − ham गिनती; score > 0 → "spam", score < 0 → "ham", वरना "unsure"।
4. 4 नए संदेशों पर Test करो, हर अंदाज़ा print करो, सही वाले गिनो और Accuracy: 1.0 print करो।
5. Responsible AI: "unsure" संदेश अपने-आप delete नहीं होना चाहिए — इंसान को जाँचना चाहिए।
Starter code
# 📱 SMS Spam Detector — bina library ke, khud ka AI!
train = [
("Congratulations you won a free iPhone click now", "spam"),
("Win cash prize now claim free offer", "spam"),
("Your KYC is expired click link to update urgent", "spam"),
("Kal school mein test hai padhai kar lena", "ham"),
("Mummy ne kaha doodh le aana", "ham"),
("Cricket match shaam 5 baje park mein", "ham"),
]
test = [
("Free offer click now to win", "spam"),
("Kal match hai park mein aana", "ham"),
("Urgent update your KYC now", "spam"),
("Doodh aur bread le aana", "ham"),
]
def clean(text):
# TODO 1: lowercase karo, "!?.," hatao, words ki list return karo
return []
spam_words = {}
ham_words = {}
# TODO 2: train ke har message ke words gino (spam_words / ham_words)
def predict(text):
# TODO 3: score = spam ginti - ham ginti; > 0 "spam", < 0 "ham", warna "unsure"
return "unsure"
correct = 0
for text, label in test:
guess = predict(text)
print(guess.upper(), "<-", text)
# TODO 4: guess == label ho to correct badhao
# TODO 5: accuracy = correct / len(test) print karo
print("Namaste ji ->", predict("Namaste ji"))