desislava_topuzakova

04. Walking

Apr 4th, 2021
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. # въвеждаме докато не получим Going home
  2. command = input()
  3. # извървени стъпки(число под формата на текст -> "2000") или "Going home"
  4. # спираме да вървим: command == "Going home"
  5. # продължаваме: command != "Going home"
  6. target_steps = 10000
  7. total_steps = 0
  8.  
  9. while command != "Going home":
  10.     # "1234" -> число
  11.     # извървени стъпки -> добавяме към общия брой -> проверка дали сме достигнали целта
  12.     walked_steps = int(command)
  13.     total_steps += walked_steps
  14.     if total_steps >= target_steps:
  15.         break
  16.     command = input()
  17. else: # command e "Going home"
  18.     steps_to_home = int(input())
  19.     total_steps += steps_to_home
  20.  
  21. # проверка достигнал ли съм целта
  22. if total_steps >= target_steps:
  23.     print("Goal reached! Good job!")
  24.     print(f"{total_steps - target_steps} steps over the goal!")
  25. else:
  26.     print(f"{target_steps - total_steps} more steps to reach goal.")
Advertisement
Add Comment
Please, Sign In to add comment