The new PIN is hard to remember. I was told that I shouldn't take notes, but I don't…
- User
The new PIN is hard to remember. I was told that I shouldn't take notes, but I don't think I can remember them. Therefore, I decided to embed a numerical value in the text and make a note of the PIN. Here, the sum of all the numbers is the PIN.
Create a program that reads the memorandum and outputs the PIN code. Input
Sentences with embedded positive integers are given over multiple lines. Each line is a character string containing single-byte alphanumeric characters, symbols, and spaces, or a blank line. However, you are guaranteed to enter no more than 80 characters per line and a PIN of 10,000 or less.
Output
The PIN (the sum of positive integers in the text) is output on one line.
Example
Input
Thereare100yenonthetable.Iam17yearsold. Ishouldgohomeat6pm.
Output
123
Assistant
pythontotal_sum = 0 while True: try: line = input() except EOFError: break current_number = 0 sum_line = 0 building = False for char in line: if char.isdigit(): current_number = current_number * 10 + int(char) building = True else: if building: if current_number > 0: sum_line += current_number current_number = 0 building = False if building: if current_number > 0: sum_line += current_number total_sum += sum_line print(total_sum)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.