Advertisement
Spocoman

03. Car Race

Jan 24th, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. time = list(map(int,input().split(' ')))
  2. left = 0
  3. right = 0
  4.  
  5. for i in range(len(time) // 2):
  6.     left += time[i]
  7.     if time[i] == 0:
  8.         left *= 0.8
  9.     right += time[len(time) - (1 + i)]
  10.     if time[len(time) - (1 + i)] == 0:
  11.         right *= 0.8
  12.  
  13. if left < right:
  14.     print(f'The winner is left with total time: {left:.1f}')
  15. else:
  16.     print(f'The winner is right with total time: {right:.1f}')
  17.  
  18. Решение с колекция:
  19.  
  20. time = list(map(int, input().split(' ')))
  21. data = {'left': 0, 'right': 0, "side": ''}
  22.  
  23. for i in range(len(time) // 2):
  24.     data['left'] += time[i]
  25.     if time[i] == 0:
  26.         data['left'] *= 0.8
  27.  
  28.     data['right'] += time[len(time) - (1 + i)]
  29.     if time[len(time) - (1 + i)] == 0:
  30.         data['right'] *= 0.8
  31.  
  32. data["side"] += 'left' if data['left'] < data['right'] else 'right'
  33. print(f'The winner is {data["side"]} with total time: {data[data["side"]]:.1f}')
  34.  
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement