Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Open the input file
- with open("input.txt", "r") as input_file:
- # Initialize the maximum number of calories
- max_calories = 0
- # Read the input
- total_calories = 0
- for line in input_file:
- line = line.strip()
- if line == "":
- # Empty line, update the maximum number of calories
- max_calories = max(max_calories, total_calories)
- total_calories = 0
- else:
- # Non-empty line, add the number of calories to the current total
- total_calories += int(line)
- # Add the last Elf's calories to the maximum (if any)
- max_calories = max(max_calories, total_calories)
- # Print the result
- print(max_calories)
Advertisement
Add Comment
Please, Sign In to add comment