From 0bec238b05324baae78fe1822bde4a1c55d8abf1 Mon Sep 17 00:00:00 2001 From: GAURAV-SINGH-07 Date: Wed, 8 Jan 2025 22:52:51 +0530 Subject: [PATCH 1/2] Added questions --- qus1.md | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qus2.md | 68 ++++++++++++++++++++++ qus3.md | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ qus4.md | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 560 insertions(+) create mode 100644 qus1.md create mode 100644 qus2.md create mode 100644 qus3.md create mode 100644 qus4.md diff --git a/qus1.md b/qus1.md new file mode 100644 index 0000000..7002a28 --- /dev/null +++ b/qus1.md @@ -0,0 +1,174 @@ +--- +title:Parking Bill Calculation System +Problem Statement +--- +# Problem Statement +Write a program that calculates the parking bill based on the following factors: + +Day Type: + +0 for weekdays. +1 for weekends. +Vehicle Type: + +0 for two-wheelers. +1 for four-wheelers. +Time of Day: + +0 for non-peak hours. +1 for peak hours. +Number of Hours: + +Parking duration in hours. +The charges are as follows: + +Weekdays: +Two-wheeler: ₹20 per hour (Non-peak), ₹20/hour + ₹20 flat (Peak). +Four-wheeler: ₹40 per hour (Non-peak), ₹40/hour + ₹30 flat (Peak). +Weekends: +Two-wheeler: ₹40 per hour (Non-peak), ₹40/hour + ₹20 flat (Peak). +Four-wheeler: ₹60 per hour (Non-peak), ₹60/hour + ₹30 flat (Peak). +Your program should prompt the user to enter the day, vehicle type, time of day, and number of hours, and then calculate and print the parking bill. +**Sample Input** +``` +Day: 0 (Weekday) +Vehicle Type: 0 (Two-wheeler) +Time: 1 (Peak Hour) +Hours: 2 +``` +**Sample Output** +``` +The bill is: ₹60 +``` +# Solution +```py test.py -r 'python3 test.py' + +``` +# Public Test Cases +## Input 1 +``` +Day: 0 +Vehicle Type: 0 +Time: 0 +Hours: 5 +``` +## Output 1 +``` +The bill is: ₹100 +``` +## Input 2 +``` +Day: 1 +Vehicle Type: 0 +Time: 1 +Hours: 2 +``` +## Output 2 +``` +The bill is: ₹100 +``` +## Input 3 +``` +Day: 1 +Vehicle Type: 1 +Time: 1 +Hours: 1 +``` +## Output 3 +``` +The bill is: ₹90 +``` + +# Private Test Cases +## Input 1 +``` +Day: 0 +Vehicle Type: 1 +Time: 1 +Hours: 3 +``` +## Output 1 +``` +The bill is: ₹150 +``` \ No newline at end of file diff --git a/qus2.md b/qus2.md new file mode 100644 index 0000000..2d403f3 --- /dev/null +++ b/qus2.md @@ -0,0 +1,68 @@ +--- +title: Key-Value Transformation in a Dictionary +tags: ['python', 'functions'] +--- +# Problem Statement +Write a function reverse_dict(d: dict) -> dict that reverses the keys and values of a dictionary. Assume values are unique and hashable. +**Sample Input** +``` +{1: 'a', 2: 'b', 3: 'c'} +``` +**Sample Output** +``` +{'a': 1, 'b': 2, 'c': 3} +``` +# Solution +```py test.py -r 'python3 test.py' + +def reverse_dict(d: dict) -> dict: + """ + Reverses the keys and values of the given dictionary. + + Arguments: + d: dict - a dictionary where the values are unique and hashable. + + Returns: + dict - a new dictionary with the keys and values reversed. + """ + + + +``` +# Public Test Cases +## Input 1 +``` +{1: 'a', 2: 'b', 3: 'c'} +``` +## Output 1 +``` +{'a': 1, 'b': 2, 'c': 3} +``` +## Input 2 +``` +{'x': 10, 'y': 20, 'z': 30} +``` +## Output 2 +``` +{10: 'x', 20: 'y', 30: 'z'} +``` +## Input 3 +``` +{100: 'apple', 200: 'banana'} +``` +## Output 3 +``` +{'apple': 100, 'banana': 200} +``` + +# Private Test Cases +## Input 1 +``` +{'cat': 1, 'dog': 2, 'mouse': 3} +``` +## Output 1 +``` +{1: 'cat', 2: 'dog', 3: 'mouse'} +``` \ No newline at end of file diff --git a/qus3.md b/qus3.md new file mode 100644 index 0000000..12ba452 --- /dev/null +++ b/qus3.md @@ -0,0 +1,159 @@ +--- +title: Process Student Scores +tags: ['python', 'functions'] +--- +# Problem Statement +Write a function process_student_scores(students: list) -> dict that processes a list of students' scores and returns a dictionary containing the following information for each subject: + + The average score for the subject. + The highest score for the subject. + The lowest score for the subject. + +Each student in the input list is represented as a dictionary with the following structure: +{ + 'name': , + 'scores': { + 'subject1': , + 'subject2': , + ... + } +} + +The function should return a dictionary with the subject names as keys and another dictionary as the value containing the average, highest, and lowest scores for each subject. +Function Signature: +def process_student_scores(students: list) -> dict: +**Sample Input** +``` +students = [ + {'name': 'Alice', 'scores': {'Math': 85, 'Science': 90}}, + {'name': 'Bob', 'scores': {'Math': 75, 'Science': 80}}, + {'name': 'Charlie', 'scores': {'Math': 95, 'Science': 85}} +] +process_student_scores(students) +``` +**Sample Output** +``` +{ + 'Math': {'average': 85.0, 'highest': 95, 'lowest': 75}, + 'Science': {'average': 85.0, 'highest': 90, 'lowest': 80} +} +``` +# Solution +```py test.py -r 'python3 test.py' + +def process_student_scores(students: list) -> dict: + """ + Processes the list of student scores and returns a dictionary containing: + - The average score for each subject. + - The highest score for each subject. + - The lowest score for each subject. + + Arguments: + students: list of dictionaries, where each dictionary contains student name and their scores in subjects. + + Returns: + dict: A dictionary where keys are subject names and values are dictionaries with 'average', 'highest', and 'lowest' scores. + """ + + + # Initialize an empty dictionary to store results + subject_stats = {} + + + # Iterate through each student + for student in students: + # Iterate through each subject score + for subject, score in student['scores'].items(): + # If subject is not in the subject_stats dictionary, initialize it + if subject not in subject_stats: + subject_stats[subject] = {'scores': [], 'average': 0, 'highest': float('-inf'), 'lowest': float('inf')} + + # Add the score to the list of scores for the subject + subject_stats[subject]['scores'].append(score) + + # Update the highest and lowest scores for the subject + if score > subject_stats[subject]['highest']: + subject_stats[subject]['highest'] = score + if score < subject_stats[subject]['lowest']: + subject_stats[subject]['lowest'] = score + + # Calculate the average score for each subject + for subject, stats in subject_stats.items(): + stats['average'] = sum(stats['scores']) / len(stats['scores']) + # Remove the scores list as it's no longer needed + del stats['scores'] + + + return subject_stats + +``` +# Public Test Cases +## Input 1 +``` +students = [ + {'name': 'Alice', 'scores': {'Math': 85, 'Science': 90}}, + {'name': 'Bob', 'scores': {'Math': 75, 'Science': 80}}, + {'name': 'Charlie', 'scores': {'Math': 95, 'Science': 85}} +] + +process_student_scores(students) +``` +## Output 1 +``` +{ + 'Math': {'average': 85.0, 'highest': 95, 'lowest': 75}, + 'Science': {'average': 85.0, 'highest': 90, 'lowest': 80} +} +``` +## Input 2 +``` +students = [ + {'name': 'Alice', 'scores': {'Math': 70, 'Science': 60}}, + {'name': 'Bob', 'scores': {'Math': 80, 'Science': 70}}, + {'name': 'Charlie', 'scores': {'Math': 90, 'Science': 80}} +] + +process_student_scores(students) +``` +## Output 2 +``` +{ + 'Math': {'average': 80.0, 'highest': 90, 'lowest': 70}, + 'Science': {'average': 70.0, 'highest': 80, 'lowest': 60} +} +``` +## Input 3 +``` +students = [ + {'name': 'Alice', 'scores': {'Math': 100}}, + {'name': 'Bob', 'scores': {'Math': 95}}, + {'name': 'Charlie', 'scores': {'Math': 90}} +] + +process_student_scores(students) +``` +## Output 3 +``` +{ + 'Math': {'average': 95.0, 'highest': 100, 'lowest': 90} +} +``` + +# Private Test Cases +## Input 1 +``` +students = [ + {'name': 'John', 'scores': {'English': 85, 'History': 75}}, + {'name': 'Jane', 'scores': {'English': 90, 'History': 80}}, + {'name': 'Alex', 'scores': {'English': 80, 'History': 85}} +] + +process_student_scores(students) +``` +## Output 1 +``` +{ + 'English': {'average': 85.0, 'highest': 90, 'lowest': 80}, + 'History': {'average': 80.0, 'highest': 85, 'lowest': 75} +} +``` \ No newline at end of file diff --git a/qus4.md b/qus4.md new file mode 100644 index 0000000..b256735 --- /dev/null +++ b/qus4.md @@ -0,0 +1,159 @@ +--- +title: Data Processing I/O +--- +# Problem Statement +Write a Python program that processes a list of student grades. The program should: + +Take a list of student names and their respective grades in multiple subjects as input. +Compute and output: +The average grade for each student. +The highest grade for each student. +The lowest grade for each student. +**Sample Input** +``` +3 +Alice 85 90 92 +Bob 78 88 82 +Charlie 95 87 91 +``` +**Sample Output** +``` +Name: Alice +Average Grade: 89.0 +Highest Grade: 92 +Lowest Grade: 85 + +Name: Bob +Average Grade: 82.67 +Highest Grade: 88 +Lowest Grade: 78 + +Name: Charlie +Average Grade: 91.0 +Highest Grade: 95 +Lowest Grade: 87 +``` +# Solution +```py test.py -r 'python3 test.py' + +``` +# Public Test Cases +## Input 1 +``` +3 +Alice 85 90 92 +Bob 78 88 82 +Charlie 95 87 91 +``` +## Output 1 +``` +Name: Alice +Average Grade: 89.0 +Highest Grade: 92 +Lowest Grade: 85 + +Name: Bob +Average Grade: 82.67 +Highest Grade: 88 +Lowest Grade: 78 + +Name: Charlie +Average Grade: 91.0 +Highest Grade: 95 +Lowest Grade: 87 +``` +## Input 2 +``` +2 +John 70 80 90 85 +Emily 95 88 92 100 +``` +## Output 2 +``` +Name: John +Average Grade: 81.25 +Highest Grade: 90 +Lowest Grade: 70 + +Name: Emily +Average Grade: 93.75 +Highest Grade: 100 +Lowest Grade: 88 +``` +## Input 3 +``` +1 +Zara 50 60 70 80 +``` +## Output 3 +``` +Name: Zara +Average Grade: 65.0 +Highest Grade: 80 +Lowest Grade: 50 +``` + +# Private Test Cases +## Input 1 +``` +Adam 50 60 70 +Eve 60 65 70 75 +Sam 100 90 95 85 +Lily 95 85 100 +``` +## Output 1 +``` +Name: Adam +Average Grade: 60.0 +Highest Grade: 70 +Lowest Grade: 50 + +Name: Eve +Average Grade: 70.0 +Highest Grade: 75 +Lowest Grade: 60 + +Name: Sam +Average Grade: 92.5 +Highest Grade: 100 +Lowest Grade: 85 + +Name: Lily +Average Grade: 93.33 +Highest Grade: 100 +Lowest Grade: 85 +``` \ No newline at end of file From eb8dc4632f019517540aa5b28c48ce7b3e1143da Mon Sep 17 00:00:00 2001 From: GAURAV-SINGH-07 Date: Wed, 8 Jan 2025 23:00:45 +0530 Subject: [PATCH 2/2] Renamed files --- qus3.md => Data_processing.md | 0 qus4.md => data_processing_IO.md | 0 qus2.md => data_types.md | 0 qus1.md => function_types.md | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename qus3.md => Data_processing.md (100%) rename qus4.md => data_processing_IO.md (100%) rename qus2.md => data_types.md (100%) rename qus1.md => function_types.md (100%) diff --git a/qus3.md b/Data_processing.md similarity index 100% rename from qus3.md rename to Data_processing.md diff --git a/qus4.md b/data_processing_IO.md similarity index 100% rename from qus4.md rename to data_processing_IO.md diff --git a/qus2.md b/data_types.md similarity index 100% rename from qus2.md rename to data_types.md diff --git a/qus1.md b/function_types.md similarity index 100% rename from qus1.md rename to function_types.md