Advertisement
Spocoman

Name Game

Feb 15th, 2022
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. name = input()
  2. winner = ""
  3. points = 0
  4.  
  5. while name != "Stop":
  6.     sum = 0
  7.     for i in range(len(name)):
  8.         num = int(input())
  9.        
  10.         if num == ord(name[i]):
  11.             sum += 10
  12.         else:
  13.             sum += 2
  14.            
  15.         if sum >= points:
  16.             winner = name
  17.             points = sum
  18.            
  19.     name = input()
  20.  
  21. print(f"The winner is {winner} with {points} points!")
  22.  
  23.  
  24. Решение с тернарен оператор:
  25.  
  26. name = input()
  27. winner = ""
  28. points = 0
  29.  
  30. while name != "Stop":
  31.     sums = 0
  32.     for i in range(len(name)):
  33.         sums += 10 if int(input()) == ord(name[i]) else 2
  34.         winner = name if sums >= points else winner
  35.         points = sums if sums >= points else points
  36.        
  37.     name = input()
  38.  
  39. print(f"The winner is {winner} with {points} points!")
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement