Advertisement
Spocoman

The Most Powerful Word

Feb 15th, 2022 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. strong = ""
  2. total = 0
  3.  
  4. while True:
  5.     word = input()
  6.     if word == "End of words":
  7.         break
  8.  
  9.     sum_ascii = 0
  10.     for i in range(len(word)):
  11.         sum_ascii += ord(word[i])
  12.  
  13.     if word[0] in "aeiouyAEIOUY":
  14.         sum_ascii *= len(word)
  15.     else:
  16.         sum_ascii /= len(word)
  17.  
  18.     if sum_ascii > total:
  19.         strong = word
  20.         total = sum_ascii
  21.  
  22. print(f"The most powerful word is {strong} - {int(total)}")
  23.  
  24.  
  25. РЕШЕНИЕ С MAP, LIST И SUM:
  26.  
  27. strong = ""
  28. total = 0
  29.  
  30. while True:
  31.     word = input()
  32.     if word == "End of words":
  33.         break
  34.  
  35.     sum_ascii = sum(map(ord, list(word)))
  36.    
  37.     if word[0] in "aeiouyAEIOUY":
  38.         sum_ascii *= len(word)
  39.     else:
  40.         sum_ascii /= len(word)
  41.  
  42.     if sum_ascii > total:
  43.         strong = word
  44.         total = sum_ascii
  45.  
  46. print(f"The most powerful word is {strong} - {int(total)}")
  47.  
  48.  
  49. ИЛИ И С ТЕРНАРЕН ОПЕРАТОР:
  50.  
  51. strong = ""
  52. total = 0
  53.  
  54. while True:
  55.     word = input()
  56.     if word == "End of words":
  57.         break
  58.  
  59.     sum_ascii = sum(map(ord, list(word)))
  60.     sum_ascii *= len(word) if word[0] in "aeiouyAEIOUY" else 1 / len(word)
  61.     strong = word if sum_ascii > total else strong
  62.     total = sum_ascii if sum_ascii > total else total
  63.  
  64. print(f"The most powerful word is {strong} - {int(total)}")
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement