Answer to Question #248940 in Python for kaavya

Question #248940
Column Title
You are given a number that denotes a column in the Excel Sheet, write a program to calculate the column name in the Excel Sheet. The naming of columns in the Excel Sheet is as follows
Column Name Column Number
A 1
B 2
C 3
... ...
X 24
Y 25
Z 26
AA 27
AB 28
... ...
BA 53
... ...
ZZ 702
AAA 703
... ...
Input
The first line of input is a positive integer.
Output
The output should be a single line containing the column name.
Explanation
For example, if the given column number is 42.
The column names with single alphabets end at 26. Further column names will contain two alphabets.
Therefore, for the column number 42, the first alphabet in the column name is A and the remaining number is (42-26) is 16.
The second alphabet of the column name is the 16th alphabet, which is P.
So, the output should be AP.
1
Expert's answer
2021-10-10T01:48:34-0400


def title(sen):
	res = 0;
	for B in range(len(sen)):
		res *= 26;
		res += ord(sen[B]) - ord('A') + 1;


	return res;
print(title("AP"));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS