"Astronomer" and "Moon starer" return True — trace through your logic manually to confirm whyget_grade(score) — it receives a number and must return the correct letter based on the grading scale described aboveclass_report(), iterate through the dictionary and print each student's name, score, and the grade returned by get_grade()class_report(), compute the average of all scores and identify the student with the highest score — print both.items() gives you both the key and the value at once. For finding the top student, think about which built-in function finds the maximum value in a collection, and how you can tell it which property of each item to compare.
[1, [2, 3], 4, [5, 6]] — and you need it flat: [1, 2, 3, 4, 5, 6]. This is a common data-cleaning task in analytics, APIs, and file parsing. Your function handles one level of nesting only — a sub-item is either a plain value or a list of plain values.
resultresult stays empty automatically.
n and returns a list of the first n Fibonacci numbers. You must solve this with a loop — no recursion.
n elements.
n elements totalresult and append it[0] and n=5 returns [0, 1, 1, 2, 3] — trace through your loop manually for n=5 to checkn - 2 elements. Each new element is the sum of the element before it and the element before that — think about negative indexing to access the last and second-to-last items without knowing their positions explicitly.
Student class must be able to calculate its own average, identify its own best and weakest subjects, and print a formatted report — all as methods. This is the classic OOP principle of keeping data and the logic that operates on it in the same place.
__init__ — store both arguments on the object so all other methods can access them via selfaverage(), highest_subject(), and lowest_subject() — each method should operate on self.scoresreport() — call the other three methods from inside it and format the output to match the expected output exactlyself — report() does not need to re-implement the average calculation, it can simply call self.average(). For the highest and lowest subjects, think about how you find a maximum or minimum value from a dictionary where the values are the scores and the keys are the subject names.
"Astronomer" / "Moon starer" — trace each step manually to confirm your cleaning and sorting logic handles spaces and mixed case correctly== in Java — there is a dedicated method in the Arrays class for comparing array contents.
HashMap where each key is a student's name and the value is their numeric score. Your program must assign a letter grade to each score, compute the class average, and identify the top student. Grading scale: 90+ → A, 80+ → B, 70+ → C, 60+ → D, below 60 → F.
getGrade() — use an if/else if chain that checks the score against each threshold in the right order and returns the appropriate letterclassReport(), iterate through the map using entrySet() and print each student's name, score, and gradenestedinstanceof check to determine whether the current item is a List or a plain Integer, and handle each case — sub-lists require an inner loop, plain values go straight into resultinstanceof keyword in Java lets you ask "is this object an instance of a particular class?" — use it to branch between the two cases. When the item is a List, you will need to cast it before you can iterate it, since the outer list holds Object references. An empty input list simply means the outer loop body never executes, so result stays as an empty ArrayList.
n and returns an ArrayList containing the first n Fibonacci numbers. Implement this with a loop — recursion is not needed here.
n - 2 times, once for each number still to be addedStudent object holds a name and a HashMap mapping subject names to scores. The class must expose methods to compute the average, find the best subject, find the weakest subject, and print a full formatted report. The report method should call the other methods — not reimplement their logic.
average(), highestSubject(), and lowestSubject() — each should iterate over the scores map using entrySet() to access both the key (subject name) and the value (score)report() — it should call the other three methods rather than recalculating anything itselfgetGrade(score) using a chain of conditionals that checks thresholds from highest to lowest and returns the correct letterclassReport(), loop over the object's entries and log each student's name, score, and the grade returned by calling getGrade()[1, [2, 3], 4, [5, 6]]. Your task is to produce a flat array with all the values in order. You must handle one level of nesting only. This data-cleaning step is extremely common when merging API responses or combining data from multiple sources.
result, and the plain value case by pushing it directlyreduce and see if you can produce the same resultinstanceof check. When the item is an array, think about which array method adds multiple elements to another array at once, versus which method adds a single element. The reduce version in Task ③ works by accumulating — starting from an empty array and merging each item into it.
n and must return an array of the first n Fibonacci numbers. Build this with a regular loop — no recursion required.
result from 2 elements up to n elementsresult, compute their sum, and push itresult looks like after each push until you reach 5 elementsStudent instance stores a name and an object mapping subject names to scores. The class must provide methods to calculate the average score, find the best subject, find the weakest subject, and print a formatted report. The report method must delegate to the other methods rather than duplicate their logic.
thisaverage(), highestSubject(), and lowestSubject() — each must work from this.scores using the keys as subject names and values as scoresreport() — iterate over the scores object to print each subject, then call the three helper methods to print the summary| id | name | department | salary | years |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Engineering' | 85000 | 5 |
| 2 | 'Priya' | 'Marketing' | 62000 | 3 |
| 3 | 'Arjun' | 'Engineering' | 92000 | 8 |
| 4 | 'Sneha' | 'HR' | 54000 | 2 |
| 5 | 'Vikram' | 'Marketing' | 71000 | 6 |
| 6 | 'Anita' | 'Engineering' | 78000 | 4 |
| 7 | 'Rohan' | 'HR' | 48000 | 1 |
| 8 | 'Divya' | 'Marketing' | 68000 | 5 |
| name | salary |
|---|---|
| Rahul | 85000 |
| Arjun | 92000 |
| Anita | 78000 |
| id | name | department | salary | years |
|---|---|---|---|---|
| 1 | Rahul | Engineering | 85000 | 5 |
| 3 | Arjun | Engineering | 92000 | 8 |
| 5 | Vikram | Marketing | 71000 | 6 |
| 6 | Anita | Engineering | 78000 | 4 |
| name |
|---|
| Sneha |
| Rohan |
| id | name | department | salary | years |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Engineering' | 85000 | 5 |
| 2 | 'Priya' | 'Marketing' | 62000 | 3 |
| 3 | 'Arjun' | 'Engineering' | 92000 | 8 |
| 4 | 'Sneha' | 'HR' | 54000 | 2 |
| 5 | 'Vikram' | 'Marketing' | 71000 | 6 |
| 6 | 'Anita' | 'Engineering' | 78000 | 4 |
| 7 | 'Rohan' | 'HR' | 48000 | 1 |
| 8 | 'Divya' | 'Marketing' | 68000 | 5 |
| name | salary |
|---|---|
| Arjun | 92000 |
| Rahul | 85000 |
| Anita | 78000 |
| name | years |
|---|---|
| Rohan | 1 |
| Sneha | 2 |
| name | salary |
|---|---|
| Vikram | 71000 |
| Divya | 68000 |
| Priya | 62000 |
| id | name | department | salary | years |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Engineering' | 85000 | 5 |
| 2 | 'Priya' | 'Marketing' | 62000 | 3 |
| 3 | 'Arjun' | 'Engineering' | 92000 | 8 |
| 4 | 'Sneha' | 'HR' | 54000 | 2 |
| 5 | 'Vikram' | 'Marketing' | 71000 | 6 |
| 6 | 'Anita' | 'Engineering' | 78000 | 4 |
| 7 | 'Rohan' | 'HR' | 48000 | 1 |
| 8 | 'Divya' | 'Marketing' | 68000 | 5 |
| COUNT(*) | SUM(salary) | AVG(salary) | MAX(salary) | MIN(salary) |
|---|---|---|---|---|
| 8 | 558000 | 69750.00 | 92000 | 48000 |
| COUNT(*) | AVG(salary) |
|---|---|
| 3 | 85000.00 |
| id | name | department | salary | years |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Engineering' | 85000 | 5 |
| 2 | 'Priya' | 'Marketing' | 62000 | 3 |
| 3 | 'Arjun' | 'Engineering' | 92000 | 8 |
| 4 | 'Sneha' | 'HR' | 54000 | 2 |
| 5 | 'Vikram' | 'Marketing' | 71000 | 6 |
| 6 | 'Anita' | 'Engineering' | 78000 | 4 |
| 7 | 'Rohan' | 'HR' | 48000 | 1 |
| 8 | 'Divya' | 'Marketing' | 68000 | 5 |
| department | COUNT(*) | AVG(salary) |
|---|---|---|
| Engineering | 3 | 85000.00 |
| HR | 2 | 51000.00 |
| Marketing | 3 | 67000.00 |
| department | SUM(salary) |
|---|---|
| Engineering | 255000 |
| HR | 102000 |
| Marketing | 201000 |
| id | name | department | salary | years |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Engineering' | 85000 | 5 |
| 2 | 'Priya' | 'Marketing' | 62000 | 3 |
| 3 | 'Arjun' | 'Engineering' | 92000 | 8 |
| 4 | 'Sneha' | 'HR' | 54000 | 2 |
| 5 | 'Vikram' | 'Marketing' | 71000 | 6 |
| 6 | 'Anita' | 'Engineering' | 78000 | 4 |
| 7 | 'Rohan' | 'HR' | 48000 | 1 |
| 8 | 'Divya' | 'Marketing' | 68000 | 5 |
| department | AVG(salary) |
|---|---|
| Engineering | 85000.00 |
| Marketing | 67000.00 |
| department | COUNT(*) |
|---|---|
| Engineering | 3 |
| Marketing | 3 |