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:
roll_number = input()- This line takes input from the user as a single string, which is the student's roll number in the formatrollNumber@institute.edu.in. The resulting string is stored in the variableroll_number.roll_parts = roll_number.split('@')- This line splits theroll_numberstring into two parts using the@symbol as the delimiter. The resulting list contains two elements: the roll number and the institute name with.edu.inat the end. The resulting list is stored in the variableroll_parts.roll = roll_parts[0]- This line extracts the first element of theroll_partslist, which is the roll number, and stores it in the variableroll.institute = roll_parts[1].split('.')[0]- This line extracts the second element of theroll_partslist, which is the institute name with.edu.inat 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 variableinstitute.print(roll, institute,end="")- This line prints the roll number and institute name withend=""to suppress the newline that is normally printed byprint().
Overall, the program takes input of a student's roll number, splits it into the roll number and institute name, and prints them out.
No comments:
Post a Comment