Advertisement
Spocoman

04. Walking

Dec 27th, 2021 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. steps = 0
  2.  
  3. while steps < 10000:
  4.     command = input()
  5.     if command == 'Going home':
  6.         steps += int(input())
  7.         break
  8.     steps += int(command)
  9.  
  10. if steps < 10000:
  11.     print(f'{10000 - steps} more steps to reach goal.')
  12. else:
  13.     print(f'Goal reached! Good job!\n{steps - 10000} steps over the goal!')
  14.  
  15. ИЛИ:
  16.  
  17. steps = 10000
  18.  
  19. while steps > 0:
  20.     command = input()
  21.     if command == 'Going home':
  22.         steps -= int(input())
  23.         break
  24.     steps -= int(command)
  25.  
  26. if steps > 0:
  27.     print(f'{steps} more steps to reach goal.')
  28. else:
  29.     print(f'Goal reached! Good job!\n{abs(steps)} steps over the goal!')
  30.  
  31. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  32.  
  33. steps = 10000
  34.  
  35. while steps > 0:
  36.     command = input()
  37.     steps -= int(command) if command != 'Going home' else int(input())
  38.     if command == 'Going home':
  39.         break
  40.  
  41. print(f'{steps} more steps to reach goal.' if steps > 0 else
  42.       f'Goal reached! Good job!\n{abs(steps)} steps over the goal!')
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement