Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions question1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
## Problem Statement

Write a function `Intro(F_name: str, L_name: str, height: float, weight: float) -> str` that:
1. Takes four parameters:
- `F_name`: First name (string).
- `L_name`: Last name (string).
- `height`: Height in meters (float).
- `weight`: Weight in kilograms (float).

2. Returns a string of the form: `"Hi, my name is XY and my BMI is __"` where:
- `X` is the first character of `F_name`.
- `Y` is the first character of `L_name`.
- BMI is calculated using the formula: `BMI = weight / (height ** 2)`.

## Solution

```python
def Intro(F_name: str, L_name: str, height: float, weight: float) -> str:
bmi = weight / (height ** 2)
return f"Hi, my name is {F_name[0]}{L_name[0]} and my BMI is {bmi:.2f}"
```

## Public Test Cases

### Test Case 1:
**Input:**
```python
("John", "Doe", 1.75, 70)
```
**Expected Output:**
```
Hi, my name is JD and my BMI is 22.86
```

### Test Case 2:
**Input:**
```python
("Alice", "Smith", 1.60, 55)
```
**Expected Output:**
```
Hi, my name is AS and my BMI is 21.48
```

## Private Test Cases

### Test Case 1:
**Input:**
```python
("James", "Bond", 1.83, 80)
```
**Expected Output:**
```
Hi, my name is JB and my BMI is 23.88
```

### Test Case 2:
**Input:**
```python
("Mark", "Ruffalo", 1.73, 72)
```
**Expected Output:**
```
Hi, my name is MR and my BMI is 24.06
```

### Test Case 3:
**Input:**
```python
("Chris", "Evans", 1.80, 85)
```
**Expected Output:**
```
Hi, my name is CE and my BMI is 26.23
```

### Test Case 4:
**Input:**
```python
("Henry", "Cavill", 1.85, 92)
```
**Expected Output:**
```
Hi, my name is HC and my BMI is 26.88
```


94 changes: 94 additions & 0 deletions question2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## Problem Statement

Write a function `group_by_first_letter(words: list) -> dict` which takes a list of words as its argument. The function should **return** a **dictionary** where:
- The **keys** of the dictionary are the first letters of ther words.
- The **values** are lists of words starting with the letter the corresponding **key**.
- Words in each list should **sorted** in **ascending alphabetical order**

### Constraints
- The input list will only contain strings.
- Words will be lowercase alphabets only (No special characters or numbers.)
- The list may contain duplicate words.

## Solution

```python
def group_by_first_letter(words: list) -> dict:
grouped = {}
for word in words:
f_letter = word[0]
if f_letter not in grouped:
grouped[f_letter] = []
grouped[first_letter].append(word)

#sorting each list of words
for key in grouped:
grouped[key].sort()

return grouped
```

## Public Test Cases

### Test Case 1:
**Input:**
```python
['apple', 'banana', 'ant', 'blueberry', 'cherry']
```
**Expected Output:**
```python
{'a': ['ant', 'apple'], 'b': ['banana', 'blueberry'], 'c': ['cherry']}
```

### Test Case 2:
**Input:**
```python
["dog", "cat", "deer", "antelope", "apple", "car"]
```
**Expected Output:**
```python
{'d': ['deer', 'dog'], 'c': ['car', 'cat'], 'a': ['antelope', 'apple']}
```

## Private Test Cases

### Test Case 1:
**Input:**
```python
["zoo", "zebra", "apple", "ant", "ant", "zebra", "antelope"]
```
**Expected Output:**
```python
{'z': ['zebra', 'zebra', 'zoo'], 'a': ['ant', 'ant', 'antelope', 'apple']}
```

### Test Case 2:
**Input:**
```python
["kiwi", "kale", "kangaroo", "apple", "ant", "banana", "caulifla"]
```
**Expected Output:**
```python
{'k': ['kale', 'kangaroo', 'kiwi'], 'a': ['ant', 'apple'], 'b': ['banana'], 'c': ['caulifla']}
```

### Test Case 3:
**Input:**
```python
["carrot", "cucumber", "celery", "date", "dragonfruit", "gogeta", "gojo"]
```
**Expected Output:**
```python
{'c': ['carrot', 'celery', 'cucumber'], 'd': ['date', 'dragonfruit'], 'g': ['gogeta', 'gojo']}
```

### Test Case 4:
**Input:**
```python
["pine", "pear", "pomegranate", "peach", "plum"]
```
**Expected Output:**
```python
{'p': ['peach', 'pear', 'pine', 'plum', 'pomegranate']}
```

144 changes: 144 additions & 0 deletions question3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
## Problem Statement

You are given the number of student `n` and their names along with their marks. Write a program to process them and print the following:
1. The total number of students.
2. The names of student who scored more than 50, sorted alphabetically.
3. The average marks of all students.

The **Input** will be in the following format:
- The first line contains an integer `n` (1 ≤ n ≤ 1000), which represents the number of students.
- Each of the next `n` lines contains a student's name and marks (separated by a space).

**Output Format:**
- Print total number of students.
- Print the list of names of students who scored above 50, sorted alphabetically.
- Print the average marks of all students, rounded to two decimal places.

*(If in doubt about output format, refer to the test cases.)*

## Solution
```python
n = int(input()) # Number of students
students = []
total_marks = 0

for i in range(n):
name, marks = input().split() # Input name and marks
marks = int(marks)
students.append((name, marks))
total_marks += marks

stud_above_50 = []
for x in students:
if x[1] > 50:
stud_above_50.append(x[0])
stud_above_50.sort()
avg_marks = total_marks/n

print(f"Total students: {n}")
print(f"Students who scored above 50: {stud_above_50}")
print(f"Average marks: {avg_marks:.2f}")
```

## Public Test Cases

### Test Case 1:
**Input:**
```
5
John 60
Alice 40
Bob 80
Charlie 55
David 45
```
**Expected Output:**
```
Total Students: 5
Students who scored above 50: ['Bob', 'Charlie', 'John']
Average marks: 56.00
```

### Test Case 2:
**Input:**
```
3
Eve 30
Frank 60
Grace 90
```
**Expected Output:**
```
Total students: 3
Students who scored above 50: ['Frank', 'Grace']
Average marks: 60.00
```

## Private Test Cases

### Test Case 1:
**Input:**
```
4
Adam 45
Ben 55
Cathy 65
Diana 75
```
**Expected Output:**
```
Total students: 4
Students who scored above 50: ['Ben', 'Cathy', 'Diana']
Average marks: 60.00
```

### Test Case 2:
**Input:**
```
6
Liam 60
Nina 80
Ivy 100
Jack 95
Maya 55
Oscar 50
```
**Expected Output:**
```
Total students: 6
Students who scored above 50: ['Ivy', 'Jack', 'Liam', 'Maya', 'Nina']
Average marks: 73.33
```

### Test Case 3:
**Input:**
```
2
Olivia 20
Paul 45
```
**Expected Output:**
```
Total students: 2
Students who scored above 50: []
Average marks: 32.50
```

### Test Case 4:
**Input:**
```
7
Fiona 85
Diana 60
Aaron 80
Ethan 45
Charlie 40
George 70
Bella 55
```
**Expected Output:**
```
Total students: 7
Students who scored above 50: ['Aaron', 'Bella', 'Diana', 'Fiona', 'George']
Average marks: 62.14
```
Loading