Advertisement
Osiris1002

Space Travel

Feb 18th, 2024
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. def travel(light_years):
  2.     global starting_fuel, abort_missing
  3.     if starting_fuel >= light_years:
  4.         starting_fuel -= light_years
  5.         print(f"The spaceship travelled {light_years} light-years.")
  6.     else:
  7.         print("Mission failed.")
  8.         abort_missing = True
  9.  
  10.  
  11. def enemy(total_enemy_armor):
  12.     global starting_ammunition, starting_fuel, abort_missing
  13.     if starting_ammunition >= total_enemy_armor:
  14.         starting_ammunition -= total_enemy_armor
  15.         print(f"An enemy with {total_enemy_armor} armour is defeated.")
  16.     elif starting_fuel >= total_enemy_armor * 2:
  17.         starting_fuel -= total_enemy_armor * 2
  18.         print(f"An enemy with {total_enemy_armor} armour is outmaneuvered.")
  19.     else:
  20.         print("Mission failed.")
  21.         abort_missing = True
  22.  
  23.  
  24. def repair(number):
  25.     global starting_ammunition, starting_fuel
  26.     starting_fuel += number
  27.     starting_ammunition += (number * 2)
  28.     print(f"Ammunitions added: {number * 2}.")
  29.     print(f"Fuel added: {number}.")
  30.  
  31.  
  32. def titan():
  33.     print("You have reached Titan, all passengers are safe.")
  34.  
  35.  
  36. route = input().split("||")
  37. starting_fuel = int(input())
  38. starting_ammunition = int(input())
  39. abort_missing = False
  40.  
  41. for command in route:
  42.     if "Titan" not in command:
  43.         command, data = [int(x) if x.isdigit() else x for x in command.split()]
  44.     else:
  45.         titan()
  46.         break
  47.     if "Travel" in command:
  48.         travel(data)
  49.     elif "Enemy" in command:
  50.         enemy(data)
  51.     elif "Repair" in command:
  52.         repair(data)
  53.     if abort_missing:
  54.         break
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement