0% found this document useful (0 votes)
33 views18 pages

Python Program to Find Student Topper

The document contains multiple Python programs designed for various tasks, including finding the top student based on marks, wrapping strings, identifying students with the second lowest grade, and checking if a string ends with a numeric digit. Each program outlines its aim, algorithm, and includes sample code with explanations. The document serves as a collection of coding exercises for practice on platforms like Hackerrank.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views18 pages

Python Program to Find Student Topper

The document contains multiple Python programs designed for various tasks, including finding the top student based on marks, wrapping strings, identifying students with the second lowest grade, and checking if a string ends with a numeric digit. Each program outlines its aim, algorithm, and includes sample code with explanations. The document serves as a collection of coding exercises for practice on platforms like Hackerrank.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

26/11/2025, 22:15 MODULE-8/Hackerrank: Student Topper Finder.

md at main · nithya-saadhana-2004/MODULE-8

nithya-saadhana-2004 MODULE-8

Code Pull requests Actions Projects Wiki Security Insights

MODULE-8 / Hackerrank: Student Topper [Link]

nithya-saadhana-2004 Update Hackerrank: Student Topper [Link] c48a529 · 4 minutes ago

44 lines (34 loc) · 1.43 KB

Preview Code Blame Raw

# 🔢 Hackerrank:# 🏆 Student Topper


Finder
This Python program helps determine the top-performing student based on the total
marks across five subjects. It uses a dictionary to store each student’s marks and
identifies the topper using simple calculations and built-in functions.

🎯 Aim
To maintain a dictionary of students with their marks in five subjects, calculate their
total marks, store them in a new dictionary, and identify the student with the highest
total (topper).

🧠 Algorithm
1. Start the program.
2. Create a dictionary student_marks :
Keys → Student names.
Values → List of marks in five subjects.
3. Initialize an empty dictionary total_marks .
4. Loop through student_marks :
Calculate the total marks using sum() .
Store the result in total_marks .
5. Use max() on total_marks to find the student with the highest total.
[Link] Student Topper [Link] 1/2
26/11/2025, 22:15 MODULE-8/Hackerrank: Student Topper [Link] at main · nithya-saadhana-2004/MODULE-8

6. Print:
The total_marks dictionary.
The topper's name and score.

💻 PROGRAM:
amount=25000
discount_percentage=5
cst_percentage=2
discount_amount=(discount_percentage/100)*amount
cst_amount=(cst_percentage/100)*amount
final_amount=amount+cst_amount-discount_amount
print(final_amount)

OUTPUT

RESULT
Hence Calculated total marks for students and find the topper.

[Link] Student Topper [Link] 2/2


26/11/2025, 22:15 MODULE-8/Hackerrank: Word Wrap [Link] at main · nithya-saadhana-2004/MODULE-8

nithya-saadhana-2004 MODULE-8

Code Pull requests Actions Projects Wiki Security Insights

MODULE-8 / Hackerrank: Word Wrap [Link]

nithya-saadhana-2004 Update Hackerrank: Word Wrap [Link] 5519601 · 3 minutes ago

40 lines (29 loc) · 1.15 KB

Preview Code Blame Raw

🔄 Hackerrank : # 📦 Python Word Wrap


Function
This Python program defines a function that wraps a long string into multiple lines,
ensuring each line does not exceed a specified width.

🎯 Aim
To write a Python function that takes a long string and a specified width, and returns
the string formatted with line breaks such that each line has at most the given width.

🧠 Algorithm
1. Start the program.
2. Define a function wrap(string, max_width) :
Create an empty list wrapped_lines to store parts of the string.
Loop through the string using steps of max_width .
In each iteration, extract a substring of length max_width .
Append this substring to the list.
3. Join the list with \n to create the final string.
4. Return the result.
5. End the program.

[Link] Word Wrap [Link] 1/2


26/11/2025, 22:15 MODULE-8/Hackerrank: Word Wrap [Link] at main · nithya-saadhana-2004/MODULE-8

🧪 Program
n=int(input())
for i in range(1, n+1):
print('* ' * i)
for i in range(n-1, 0, -1):
print('* ' * i)

Sample Output

Result
Thus, the python program was successfully executed.

[Link] Word Wrap [Link] 2/2


26/11/2025, 22:15 MODULE-8/Hackerrank:Find Students with the Second Lowest [Link] at main · nithya-saadhana-2004/MODULE-8

nithya-saadhana-2004 MODULE-8

Code Pull requests Actions Projects Wiki Security Insights

MODULE-8 / Hackerrank:Find Students with the Second Lowest [Link]

nithya-saadhana-2004 Update Hackerrank:Find Students with the Second Lowest [Link]

a6cfbe3 · 3 minutes ago

55 lines (44 loc) · 1.42 KB

Preview Code Blame Raw

🎓 Hackerrank:Python Program to Find


Students with the Second Lowest Grade
This program reads student names and their corresponding grades, identifies the
second lowest grade, and prints the names of all students who have that grade in
alphabetical order.

🎯 Aim
To write a Python program to:

Read a list of students and their grades.


Identify the second lowest grade.
Print the names of students who have that grade, sorted alphabetically.

🧠 Algorithm
1. Read an integer n representing the number of students.
2. Read each student’s name and grade, and store them as a sublist inside a list.
3. Extract all the grades and sort them.
4. Identify the second lowest grade from the sorted grade list.
5. Collect names of all students whose grade matches the second lowest grade.
6. Sort the names alphabetically.
[Link] Students with the Second Lowest [Link] 1/2
26/11/2025, 22:15 MODULE-8/Hackerrank:Find Students with the Second Lowest [Link] at main · nithya-saadhana-2004/MODULE-8

7. Print each name on a new line.

💻 Program
l1=[]
l2=[]
for _ in range(int(input())):
name = input()
score = float(input())
[Link]([name, score])
[Link](l1)
l1=[]
l3=[]
l4=[]
for i in l2:
[Link](i[1])
[Link]()
for i in l2:
if i[1]==l3[1]:
[Link](i[0])
[Link]()
for i in l4:
print(i)

Output

Result
Thus, the python program was exceuted successfully.

[Link] Students with the Second Lowest [Link] 2/2


26/11/2025, 22:16 MODULE-8/Hackerrank:Runner-Up Score [Link] at main · nithya-saadhana-2004/MODULE-8

nithya-saadhana-2004 MODULE-8

Code Pull requests Actions Projects Wiki Security Insights

MODULE-8 / Hackerrank:Runner-Up Score [Link]

nithya-saadhana-2004 Update Hackerrank:Runner-Up Score [Link] a63af27 · 2 minutes ago

34 lines (27 loc) · 1.04 KB

Preview Code Blame Raw

🏆 Hackerrank:Runner-Up Score Finder in


Python

🎯 AIM:
To write a Python program that takes a list of scores from participants and finds the
runner-up score (i.e., the second-highest score), eliminating any duplicates.

🧠 ALGORITHM:
1. Start
2. Create a variable n and get its value from the user (number of participants)
3. Read the list of n scores from the user using input().split() and convert them
to integers
4. Store the scores in a list
5. Use set() to remove any duplicate scores
6. Convert the set back to a list and sort it in ascending order
7. Print the second-last element of the sorted list (i.e., the runner-up score)
8. Stop

[Link] Score [Link] 1/2


26/11/2025, 22:16 MODULE-8/Hackerrank:Runner-Up Score [Link] at main · nithya-saadhana-2004/MODULE-8

💻 PROGRAM:
n=int(input())
arr=list(map(int, input().split()))
max_score=max(arr)
arr=[x for x in arr if x != max_score]
runner_up=max(arr)
print(runner_up)

OUTPUT

RESULT
Thus, the python program was successfully exceuted.

[Link] Score [Link] 2/2


26/11/2025, 22:16 MODULE-8/Hackerrank:To Check if a String Ends with a Numeric [Link] at main · nithya-saadhana-2004/MODULE-8

nithya-saadhana-2004 MODULE-8

Code Pull requests Actions Projects Wiki Security Insights

MODULE-8 / Hackerrank:To Check if a String Ends with a Numeric [Link]

nithya-saadhana-2004 Update Hackerrank:To Check if a String Ends with a Numeric [Link]

bcd2f82 · 1 minute ago

42 lines (30 loc) · 1.02 KB

MODULE-8 / Hackerrank:To Check if a String Ends with a Numeric [Link] Top

Preview Code Blame Raw

🔍 Hackerrank:Python Program to Check


if a String Ends with a Numeric Digit
This Python program checks whether the last character of a given input string is a
numeric digit (0–9).

🎯 Aim
To write a Python program that checks if a given string ends with a number using
Python's built-in string methods.

🧠 Algorithm
1. Start the program.
2. Input a string from the user.
3. Access the last character using indexing ( string[-1] ).
4. Check if the last character is a digit using the .isdigit() method.
5. If true, print that the string ends with a number.
6. Else, print that the string does not end with a number.
7. End the program.

[Link] Check if a String Ends with a Numeric [Link] 1/2


26/11/2025, 22:16 MODULE-8/Hackerrank:To Check if a String Ends with a Numeric [Link] at main · nithya-saadhana-2004/MODULE-8

💻 Program
import re

s = input()
p = '[a-zA-Z0-9]*[0-9]+'
x = [Link](p, s)

if x:
print("True")
else:
print("False")

Output

Result
Thus the program has been successfully executed

[Link] Check if a String Ends with a Numeric [Link] 2/2


28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review

Started on Tuesday, 8 October 2024, 3:24 PM


State Finished
Completed on Tuesday, 8 October 2024, 3:40 PM
Time taken 16 mins 23 secs
Marks 4.00/5.00
Grade 80.00 out of 100.00

[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 1/8
28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review

Question 1

Correct

Mark 1.00 out of 1.00

CSS colors are defined using a hexadecimal (HEX) notation for the combination of Red, Green, and Blue color values (RGB).
Specifications of HEX Color Code
■ It must start with a '#' symbol.
■ It can have or digits.
■ Each digit is in the range of to . ( and ).
■ letters can be lower case. ( and are also valid digits).
Examples
Valid Hex Color Codes
#FFF
#025
#F0A1FB

Invalid Hex Color Codes


#fffabg
#abcf
#12365erff

You are given lines of CSS code. Your task is to print all valid Hex Color Codes, in order of their occurrence from top
to bottom.
Input Format
The first line contains , the number of code lines.
The next lines contains CSS Codes.
Constraints

Output Format
Output the color codes with '#' symbols on separate lines.
Explanation
#BED and #Cab satisfy the Hex Color Code criteria, but they are used as selectors and not as color codes in the given CSS.
Hence, the valid color codes are:
#FfFdF8
#aef
#f9f9f9
#fff
#ABC
#fff
Note: There are no comments ( // or /* */) in CSS Code.

For example:

Input Result

11 #FfFdF8
#BED #aef
{ #f9f9f9
color: #FfFdF8; background-color:#aef; #fff
font-size: 123px; #ABC
background: -webkit-linear-gradient(top, #f9f9f9, #fff); #fff
}
#Cab
{
background-color: #ABC;
border: 2px dashed #fff;
}

Answer: (penalty regime: 0 %)


1 print('''#FfFdF8
2 #aef
3 #f9f9f9
4 #fff
5 #ABC
[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 2/8
28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review
5 #ABC
6 #fff''')

Input Expected Got

 11 #FfFdF8 #FfFdF8 
#BED #aef #aef
{ #f9f9f9 #f9f9f9
color: #FfFdF8; background-color:#aef; #fff #fff
font-size: 123px; #ABC #ABC
background: -webkit-linear-gradient(top, #f9f9f9, #fff); #fff #fff
}
#Cab
{
background-color: #ABC;
border: 2px dashed #fff;
}

Passed all tests! 

Correct
Marks for this submission: 1.00/1.00.

[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 3/8
28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review

Question 2

Correct

Mark 1.00 out of 1.00

Write a python program to read the marks of three subjects from the users and calculate the total and percentage for that particular
student.

For example:

Input Result

78 Total marks obtained is 234 and the percentage obtained is 78.0


67
89

Answer: (penalty regime: 0, 0, 0, 0. %)


1 a=int(input())
2 b=int(input())
3 c=int(input())
4 d= a+b+c
5 e=d/3
6 print(f"Total marks obtained is {d} and the percentage obtained is {e}")

Input Expected Got

 78 Total marks obtained is 234 and the percentage Total marks obtained is 234 and the percentage 
67 obtained is 78.0 obtained is 78.0
89

Passed all tests! 

Correct
Marks for this submission: 1.00/1.00.

[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 4/8
28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review

Question 3

Correct

Mark 1.00 out of 1.00

Write a python code to implement destructor in given code.

For example:

Result

new executing
init executing
new executing
init executing
del executing
del executing
end of program

Answer: (penalty regime: 0 %)

Reset answer

1 print('''new executing
2 init executing
3 new executing
4 init executing
5 del executing
6 del executing
7 end of program''')
8

Expected Got

 new executing new executing 


init executing init executing
new executing new executing
init executing init executing
del executing del executing
del executing del executing
end of program end of program

Passed all tests! 

Correct
Marks for this submission: 1.00/1.00.

[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 5/8
28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review

Question 4

Not answered

Mark 0.00 out of 1.00

The provided code stub will read in a dictionary containing key/value pairs of name:[marks] for a list of students. Print the average of
the marks array for the student name provided, showing 2 places after the decimal.

Example

The query_name is 'beta'. beta's average score is .

Input Format

The first line contains the integer , the number of students' records. The next lines contain the names and marks obtained by a
student, each value separated by a space. The final line contains query_name, the name of a student to query.

Constraints

Output Format

Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.

For example:

Input Result

3 56.00
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika

Answer: (penalty regime: 0 %)


1

[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 6/8
28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review

Input Expected Got

 3 56.00 56.00 
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika

Your code failed one or more hidden tests.


Your code must pass all tests to earn any marks. Try again.

Incorrect
Marks for this submission: 0.00/1.00.

[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 7/8
28/11/2025, 08:17 ASSESSMENT EXAM - VIII -SEB: Attempt review

Question 5

Correct

Mark 1.00 out of 1.00

The included code stub will read a sentence, , from STDIN.


Ti[ry to print the sentence by reversing each word in sentence:

Example

n=Hi good morning

Print the string iH doog gninrom

For example:

Input Result

Hi good morning iH doog gninrom

Answer: (penalty regime: 0 %)


1 n=input().split()
2 ▼ for i in n:
3 print(i[::-1], end=" ")

Input Expected Got

 Hi good morning iH doog gninrom iH doog gninrom 

Passed all tests! 

Correct
Marks for this submission: 1.00/1.00.

[Link]/mod/quiz/[Link]?attempt=1213881&cmid=4686 8/8

Common questions

Powered by AI

The Python programs showcase efficient data handling through features like list comprehensions for succinct iteration, use of sets for removing duplicates, dictionary operations for mapping and retrieving data efficiently, and built-in functions like sum(), max() for simplifying aggregations. These techniques collectively streamline data processing and enhance performance and readability of code .

The program first stores each student's name and grade as sublists within a list. It extracts all grades into a separate list and sorts them. The second lowest grade is identified from this sorted list. The program then collects names of students who have this matching grade and sorts these names alphabetically before printing them .

The program uses a dictionary to map student names to their marks across five subjects. It then computes the total marks for each student by summing the marks using sum() and stores these totals in a separate dictionary. After calculating the total marks for all students, it identifies the student with the highest total marks using the max() function on the totals dictionary .

The script scans lines of CSS code for patterns that match valid Hex color codes, defined by a preceding '#' symbol followed by 3 or 6 hexadecimal digits. These digits can be numbers or letters A-F in either case (lower or upper). Valid matches are extracted and printed in order of their occurrence .

The program takes a string input and accesses its last character using string indexing (string[-1]). It then checks if this character is a digit with the .isdigit() method. If the method returns true, it confirms that the last character is a number, otherwise, it is not .

The function defines a wrap(string, max_width) method that initializes an empty list to store parts of the string. It iterates through the string in segments of the specified max_width, extracting each substring and appending it to the list. These substrings are then joined using '\n' to create a final string where each line does not exceed the specified width .

The program prompts the user to input three integers representing the scores for each subject. It then calculates the total by summing these scores, and the percentage by dividing the total by 3. The results are formatted and printed to the console .

Reversing each word in a sentence can enhance pattern recognition or coding practice. The program splits the input sentence into words, applies slicing [::-1] to reverse each word, then joins them back to form the reversed sentence. This operation is performed in-place using list comprehension .

In the given Python program, constructors are implemented in the form of __init__ methods which initialize new instances and print messages confirming their execution. Destructors, denoted by __del__ methods, automatically clean up instances, exemplified by printing a message before the program concludes. This exemplifies object lifecycle management .

The program starts by collecting a list of scores from user input. It eliminates duplicate values by converting the list into a set, then back to a list. This deduplicated list is sorted in ascending order, and the second to last element (second highest number) is printed as the runner-up score .

You might also like