Showing posts with label write a program to find the roll number and institute name of the student.. Show all posts
Showing posts with label write a program to find the roll number and institute name of the student.. Show all posts
Sunday, April 9, 2023

Given a student's roll number in the following format rollNumber@institute.edu.in, write a program to find the roll number and institute name of the student.



Given a student's roll number in the following format rollNumber@institute.edu.in, write a program to find the roll number and institute name of the student.


Input:
roll@institute.edu.in

Output:
roll institute

Python Code:

# Take input of student's roll number in the format rollNumber@institute.edu.in
roll_number = input()

# Split the roll number using the '@' symbol as the delimiter
roll_parts = roll_number.split('@')

# Extract the roll number and institute name from the split parts
roll = roll_parts[0]
institute = roll_parts[1].split('.')[0]

# Print the roll number and institute name
print(roll, institute,end="")


Explanation:

This is a Python program that takes input of a student's roll number in the format rollNumber@institute.edu.in, extracts the roll number and institute name from it, and prints them out. Here's an explanation of how the program works:

  1. roll_number = input() - This line takes input from the user as a single string, which is the student's roll number in the format rollNumber@institute.edu.in. The resulting string is stored in the variable roll_number.
  2. roll_parts = roll_number.split('@') - This line splits the roll_number string into two parts using the @ symbol as the delimiter. The resulting list contains two elements: the roll number and the institute name with .edu.in at the end. The resulting list is stored in the variable roll_parts.
  3. roll = roll_parts[0] - This line extracts the first element of the roll_parts list, which is the roll number, and stores it in the variable roll.
  4. institute = roll_parts[1].split('.')[0] - This line extracts the second element of the roll_parts list, which is the institute name with .edu.in at the end. It then splits this element into a list using . as the delimiter and extracts the first element of the resulting list, which is the institute name without .edu.in. The resulting string is stored in the variable institute.
  5. print(roll, institute,end="") - This line prints the roll number and institute name with end="" to suppress the newline that is normally printed by print().

Overall, the program takes input of a student's roll number, splits it into the roll number and institute name, and prints them out.