Guest User

Untitled

a guest
Dec 1st, 2022
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # Open the input file
  2. with open("input.txt", "r") as input_file:
  3.   # Initialize the maximum number of calories
  4.   max_calories = 0
  5.  
  6.   # Read the input
  7.   total_calories = 0
  8.   for line in input_file:
  9.     line = line.strip()
  10.     if line == "":
  11.       # Empty line, update the maximum number of calories
  12.       max_calories = max(max_calories, total_calories)
  13.       total_calories = 0
  14.     else:
  15.       # Non-empty line, add the number of calories to the current total
  16.       total_calories += int(line)
  17.  
  18.   # Add the last Elf's calories to the maximum (if any)
  19.   max_calories = max(max_calories, total_calories)
  20.  
  21.   # Print the result
  22.   print(max_calories)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment