Renamed all folders

This commit is contained in:
2021-04-16 16:58:48 +02:00
parent dbc6cfef05
commit 197b3eea8a
62 changed files with 0 additions and 0 deletions

40
022/main.py Normal file
View File

@@ -0,0 +1,40 @@
import os
import math
import numpy as np
# Calculate the sum of all scores of the names in the textfile, where
# the score is the product of the sorted position and
# sum of alphabetic values of its letters
def charScore(c):
assert len(c) == 1
return ord(c.lower()) - 96
def strScore(s):
res = 0
for c in s:
res = res + charScore(c)
return res
def main():
print("Hello, this is Patrick")
f = open("names.txt", 'r')
names = f.readline()
f.close()
names = names.strip('\"').split("\",\"")
names.sort()
scores = []
for i in range(len(names)):
n = names[i]
score = strScore(n) * (i + 1)
scores.append(score)
print(sum(scores))
if __name__ == "__main__":
main()