-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExcelToColumn.py
52 lines (39 loc) · 926 Bytes
/
ExcelToColumn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# GHC_Codepath
# SE101
# Sandbox - 3
# Given a column as represented in excel, return
# its corresponding column number.
# Example:
#
# A => 1
# B => 2
# C => 3
# ...
# Z => 26
# AA => 27
# AB => 28
#!/bin/python3
import math
import os
import random
import re
import sys
# The function is expected to return an INTEGER.
# The function accepts STRING column as parameter.
def excel_column_to_number(column):
answer = 0
# to keep current count of power of 26
power = 1
# looping in reverse order
for i in range(len(column)-1, -1, -1):
# to store alphas value between 1-26
temp = ord(column[i]) - ord('A') + 1
answer += temp*power
power *= 26
return answer
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
column = input()
result = excel_column_to_number(column)
fptr.write(str(result) + '\n')
fptr.close()