DAY 01 · PRACTICE

5 Questions — Try It Yourself 💪

📦 Topics: Collections · OOP · Data Structures ⏱ Est: 1.5–2.5 hrs total 🎯 Difficulty: 2 / 5
01
Student Marks Manager 📝
LIST DICT EASY ~25 min
📖 Scenario
You are a teacher with a list of students and their marks. Each student is stored as a dictionary with two keys: "name" and "marks". Write a program that automatically calculates the class results.
Starter Code
students = [ {"name": "Rahul", "marks": 72}, {"name": "Priya", "marks": 85}, {"name": "Arjun", "marks": 40}, {"name": "Sneha", "marks": 91}, {"name": "Vikram", "marks": 55}, ] # Write your code below
Your Tasks
  • Calculate the average marks of the whole class Add up all marks, then divide by number of students
  • Make a list of students who passed (marks >= 50) Return only their names, not the whole dictionary
  • Make a list of students who failed (marks < 50) Return only their names
  • Print the topper's name — student with the highest marks
Expected Output
Average: 68.6
Pass: ['Rahul', 'Priya', 'Sneha', 'Vikram']
Fail: ['Arjun']
Topper: Sneha (91 marks)
💡 One Hint
Use for s in students: to loop. Access each student's marks with s["marks"] and name with s["name"].
02
Cricket Score Tracker 🏏
TUPLE LIST EASY ~20 min
📖 Scenario
You are building a cricket scorecard app. Each player's score is stored as a tuple(player_name, runs). Tuples are used because a match score is fixed and should never change after recording.
Starter Code
scores = [ ("Rohit", 83), ("Virat", 45), ("Dhoni", 67), ("Hardik", 32), ("Bumrah", 12), ("Shubman", 91), ] # scores[0] = ("Rohit", 83) # scores[0][0] = "Rohit", scores[0][1] = 83 # Write your code below
Your Tasks
  • Calculate the total runs scored by the whole team
  • Find the highest scorer — print their name and runs
  • List all players who scored 50 or more runs Return the full tuples (name, runs) for these players
  • Calculate the team average (total / number of players)
Expected Output
Total runs: 330
Highest scorer: Shubman - 91 runs
50+ scorers: [('Rohit', 83), ('Dhoni', 67), ('Shubman', 91)]
Team average: 55.0
💡 One Hint
In each tuple, index [0] is the name and index [1] is the runs. You can also unpack like this: for name, runs in scores:
03
Common Friends Finder 👫
SET EASY ~20 min
📖 Scenario
Think of Instagram's "Mutual Friends" feature. Two people each have a friend list. You need to find who they share, who is exclusive to one person, and the full combined list. Sets are perfect here — they automatically remove duplicates!
Starter Code
rahul_friends = {"Amit", "Priya", "Rohan", "Sneha", "Karan"} priya_friends = {"Rohan", "Sneha", "Ankit", "Divya"} # {} with no key:value = SET (not a dictionary!) # Write your code below
Your Tasks
  • Find common friends — friends that BOTH have Use the & operator
  • Find friends that are only Rahul's — Priya doesn't have them Use the - operator
  • Make a combined list of ALL friends — no duplicates Use the | operator
  • Print the total count of unique friends
Expected Output
Common: {'Rohan', 'Sneha'}
Only Rahul's: {'Amit', 'Priya', 'Karan'}
All friends: {'Amit', 'Priya', 'Rohan', 'Sneha', 'Karan', 'Ankit', 'Divya'}
Total unique: 7
💡 One Hint
Sets have 3 built-in operators: & = common, - = only left side, | = everything combined. No loops needed!
04
Phone Book Manager 📱
DICTIONARY EASY ~25 min
📖 Scenario
A phone contact list is basically a dictionary — each name maps to a number. In Python, a dictionary stores key → value pairs. You search by name (key) and instantly get the number (value) — no looping through everything!
Starter Code
phone_book = { "Rahul": "9876543210", "Priya": "9123456789", "Arjun": "9988776655", } # Write your code below — complete each task one by one
Your Tasks
  • Add a new contact: "Sneha" → "9001122334"
  • Search for "Priya" — print her number if she exists Check if she exists before accessing, to avoid errors
  • Delete "Arjun" from the phone book
  • Print all contacts in alphabetical order
  • Search for "Virat" — if not found, print "Contact not found!" without crashing There is a safe dictionary method for this!
Expected Output
Sneha added!
Priya's number: 9123456789
Arjun deleted!
All contacts: Priya | Rahul | Sneha
Searching Virat... Contact not found!
💡 One Hint
For Task 5, using phone_book["Virat"] will crash if Virat doesn't exist. Use phone_book.get("Virat", "Contact not found!") instead — it returns the default value safely.
05
Simple Student Class 🎓
OOP EASY ~30 min
📖 Scenario
Instead of writing separate code for each student, create a Class — a blueprint. Then create individual student objects from it. A Topper subclass inherits everything from Student and adds scholarship logic. This is the core idea of OOP!
Starter Code
class Student: def __init__(self, name, roll_no, marks): pass # store name, roll_no, marks using self def get_grade(self): pass # return 'A', 'B', or 'C' def display(self): pass # print name, roll no, marks, grade class Topper(Student): def __init__(self, name, roll_no, marks): pass # call super().__init__ here def get_scholarship(self): pass # return scholarship amount
Your Tasks
  • Fill __init__ — store name, roll_no, marks using self
  • Fill get_grade() — return "A" if marks>=80, "B" if marks>=60, else "C"
  • Fill display() — print all info neatly, call self.get_grade() inside it
  • Fill Topper.__init__ — call super().__init__() so it inherits from Student
  • Fill get_scholarship() — "₹10,000" if marks>=90, else "No scholarship"
Expected Output
s1 = Student("Rahul", 101, 75) → s1.display()
Rahul | Roll: 101 | Marks: 75 | Grade: B

t1 = Topper("Sneha", 102, 95) → t1.display()
Sneha | Roll: 102 | Marks: 95 | Grade: A
t1.get_scholarship() → ₹10,000
💡 One Hint
Every method in a class needs self as its first parameter. self.name = name saves the value to the object. In Topper, don't forget super().__init__(name, roll_no, marks) — otherwise name/marks won't be set!
01
Student Marks Manager 📝
ARRAYLIST HASHMAP EASY ~25 min
📖 Scenario
You are a teacher with a list of students and their marks. Each student's data is stored in a String[] array (name at index 0, marks at index 1). Use an ArrayList to hold all students. Write a program that automatically calculates class results.
Starter Code
import java.util.*; public class MarksManager { public static void main(String[] args) { ArrayList<String[]> students = new ArrayList<>(); students.add(new String[]{"Rahul", "72"}); students.add(new String[]{"Priya", "85"}); students.add(new String[]{"Arjun", "40"}); students.add(new String[]{"Sneha", "91"}); students.add(new String[]{"Vikram", "55"}); // Write your code below } }
Your Tasks
  • Calculate the average marks of the whole class Use Integer.parseInt(s[1]) to convert String marks to int
  • Make a list of students who passed (marks >= 50) Print only their names using s[0]
  • Make a list of students who failed (marks < 50) Print only their names
  • Print the topper's name — student with the highest marks
Expected Output
Average: 68.6
Pass: [Rahul, Priya, Sneha, Vikram]
Fail: [Arjun]
Topper: Sneha (91 marks)
💡 One Hint
Loop with for (String[] s : students). Access name via s[0] and marks via Integer.parseInt(s[1]). For average, cast to double: (double) total / students.size().
02
Cricket Score Tracker 🏏
2D ARRAY ARRAYLIST EASY ~20 min
📖 Scenario
You are building a cricket scorecard app. Each player's score is stored as a String[] with 2 elements{name, runs}. Since match scores are fixed after recording, we use a simple array per player and store them all in one list.
Starter Code
import java.util.*; public class CricketTracker { public static void main(String[] args) { String[][] scores = { {"Rohit", "83"}, {"Virat", "45"}, {"Dhoni", "67"}, {"Hardik", "32"}, {"Bumrah", "12"}, {"Shubman", "91"}, }; // scores[0][0] = "Rohit", scores[0][1] = "83" // Write your code below } }
Your Tasks
  • Calculate the total runs scored by the whole team
  • Find the highest scorer — print their name and runs
  • List all players who scored 50 or more runs Print name and runs for each qualifying player
  • Calculate the team average (total / number of players)
Expected Output
Total runs: 330
Highest scorer: Shubman - 91 runs
50+ scorers: Rohit(83), Dhoni(67), Shubman(91)
Team average: 55.0
💡 One Hint
Loop with for (String[] p : scores). Use p[0] for name and Integer.parseInt(p[1]) for runs. Track the max using a variable that you update inside the loop.
03
Common Friends Finder 👫
HASHSET EASY ~20 min
📖 Scenario
Think of Instagram's "Mutual Friends" feature. Two people each have a friend list. Use Java's HashSet — it automatically removes duplicates and has built-in methods for intersection, difference, and union operations.
Starter Code
import java.util.*; public class FriendFinder { public static void main(String[] args) { HashSet<String> rahulFriends = new HashSet<>( Arrays.asList("Amit", "Priya", "Rohan", "Sneha", "Karan") ); HashSet<String> priyaFriends = new HashSet<>( Arrays.asList("Rohan", "Sneha", "Ankit", "Divya") ); // Write your code below } }
Your Tasks
  • Find common friends — friends that BOTH have Create a copy and use .retainAll() method
  • Find friends that are only Rahul's — Priya doesn't have them Create a copy and use .removeAll() method
  • Make a combined list of ALL friends — no duplicates Create a copy and use .addAll() method
  • Print the total count of unique friends
Expected Output
Common: [Rohan, Sneha]
Only Rahul's: [Amit, Priya, Karan]
All friends: [Amit, Priya, Rohan, Sneha, Karan, Ankit, Divya]
Total unique: 7
💡 One Hint
Always work on a copynew HashSet<>(rahulFriends) — so the original set isn't modified. Then call copy.retainAll(priyaFriends) to keep only common elements.
04
Phone Book Manager 📱
HASHMAP TREEMAP EASY ~25 min
📖 Scenario
A phone contact list is a classic HashMap in Java — each name (key) maps to a number (value). Use TreeMap when you need contacts in sorted/alphabetical order, since HashMap doesn't guarantee any order.
Starter Code
import java.util.*; public class PhoneBook { public static void main(String[] args) { HashMap<String, String> phoneBook = new HashMap<>(); phoneBook.put("Rahul", "9876543210"); phoneBook.put("Priya", "9123456789"); phoneBook.put("Arjun", "9988776655"); // Write your code below — complete each task one by one } }
Your Tasks
  • Add a new contact: "Sneha" → "9001122334"
  • Search for "Priya" — print her number if she exists Use .containsKey() before accessing to avoid errors
  • Delete "Arjun" from the phone book using .remove()
  • Print all contacts in alphabetical order Hint: use a TreeMap for automatic sorting
  • Search for "Virat" — if not found, print "Contact not found!" without crashing Use .getOrDefault() for safe lookup
Expected Output
Sneha added!
Priya's number: 9123456789
Arjun deleted!
All contacts: Priya | Rahul | Sneha
Searching Virat... Contact not found!
💡 One Hint
Use phoneBook.getOrDefault("Virat", "Contact not found!") — it returns the value if key exists, otherwise returns your default string safely without throwing an exception.
05
Simple Student Class 🎓
OOP INHERITANCE EASY ~30 min
📖 Scenario
Instead of writing separate code for each student, create a Class — a blueprint. Then create individual student objects from it. A Topper subclass extends Student and adds scholarship logic using Java's extends keyword and super() constructor call.
Starter Code
class Student { String name; int rollNo, marks; Student(String name, int rollNo, int marks) { // TODO: assign to this.name, this.rollNo, this.marks } String getGrade() { // TODO: return "A" / "B" / "C" return ""; } void display() { // TODO: print name | rollNo | marks | grade } } class Topper extends Student { Topper(String name, int rollNo, int marks) { super(name, rollNo, marks); // calls Student's constructor } String getScholarship() { // TODO: return "₹10,000" or "No scholarship" return ""; } } public class Main { public static void main(String[] args) { Student s1 = new Student("Rahul", 101, 75); s1.display(); Topper t1 = new Topper("Sneha", 102, 95); t1.display(); System.out.println(t1.getScholarship()); } }
Your Tasks
  • Fill the Student constructor — assign this.name = name, etc.
  • Fill getGrade() — return "A" if marks>=80, "B" if marks>=60, else "C"
  • Fill display() — print all info neatly, call getGrade() inside it
  • The super() in Topper is already there — understand why it's needed
  • Fill getScholarship() — return "₹10,000" if marks>=90, else "No scholarship"
Expected Output
Rahul | Roll: 101 | Marks: 75 | Grade: B

Sneha | Roll: 102 | Marks: 95 | Grade: A
₹10,000
💡 One Hint
In Java, use this.name = name inside the constructor to distinguish the field from the parameter. In getGrade(), use if-else if-else with this.marks. The super() call in Topper must be the first line of the constructor!