Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- strong = ""
- total = 0
- while True:
- word = input()
- if word == "End of words":
- break
- sum_ascii = 0
- for i in range(len(word)):
- sum_ascii += ord(word[i])
- if word[0] in "aeiouyAEIOUY":
- sum_ascii *= len(word)
- else:
- sum_ascii /= len(word)
- if sum_ascii > total:
- strong = word
- total = sum_ascii
- print(f"The most powerful word is {strong} - {int(total)}")
- РЕШЕНИЕ С MAP, LIST И SUM:
- strong = ""
- total = 0
- while True:
- word = input()
- if word == "End of words":
- break
- sum_ascii = sum(map(ord, list(word)))
- if word[0] in "aeiouyAEIOUY":
- sum_ascii *= len(word)
- else:
- sum_ascii /= len(word)
- if sum_ascii > total:
- strong = word
- total = sum_ascii
- print(f"The most powerful word is {strong} - {int(total)}")
- ИЛИ И С ТЕРНАРЕН ОПЕРАТОР:
- strong = ""
- total = 0
- while True:
- word = input()
- if word == "End of words":
- break
- sum_ascii = sum(map(ord, list(word)))
- sum_ascii *= len(word) if word[0] in "aeiouyAEIOUY" else 1 / len(word)
- strong = word if sum_ascii > total else strong
- total = sum_ascii if sum_ascii > total else total
- print(f"The most powerful word is {strong} - {int(total)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement