dia 1 en python

main
Jaime9070 2023-12-02 11:14:37 +01:00
parent 9b3ff2be57
commit 1209bb95c0
3 changed files with 73 additions and 0 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
**/debug/ **/debug/
**/target/ **/target/
**/*rs.bk **/*rs.bk
**/calibration_document.txt

View File

@ -0,0 +1,36 @@
#Import the module that give us access to work with files. Allows us to manage the file-related input.
from io import open
# We open the txt document containing the calibration code
calibration_document=open('calibration_document.txt','r')
# We read the text inside distinguishing by lines
text=calibration_document.readlines()
# Close the txt file to be able to work on the text without having the file open.
calibration_document.close()
del(calibration_document)
# Define the digits that we want to search in the text
numbers = ['0','1','2','3','4','5','6','7','8','9']
calibration_value=0
list_numbers=[]
# Combining the first digit and the last digit to form a single two-digit number to obtein the calibration values
for line in text:
code=''
for letter in line:
if letter in numbers:
code=code+letter
break
for letter in line[::-1]:
if letter in numbers:
code=code+letter
break
list_numbers.append(int(code))
# The sum of all of the calibration values is the solution of the problem to to repare the trebuchet
calibration_values=sum(list_numbers)
#print(list_numbers)
print('The calibration value is {}'.format(calibration_values))

View File

@ -0,0 +1,36 @@
#Import the module that give us access to work with files. Allows us to manage the file-related input.
from io import open
# We open the txt document containing the calibration code
calibration_document=open('calibration document.txt','r')
# We read the text inside distinguishing by lines
text=calibration_document.readlines()
# Close the txt file to be able to work on the text without having the file open.
calibration_document.close()
del(calibration_document)
# Define the digits that we want to search in the text
numbers = ['0','1','2','3','4','5','6','7','8','9']
calibration_value=0
list_numbers=[]
# Combining the first digit and the last digit to form a single two-digit number to obtein the calibration values
for line in text:
code=''
for letter in line:
if letter in numbers:
code=code+letter
break
for letter in line[::-1]:
if letter in numbers:
code=code+letter
break
list_numbers.append(int(code))
# The sum of all of the calibration values is the solution of the problem to to repare the trebuchet
calibration_values=sum(list_numbers)
#print(list_numbers)
print('The calibration value is {}'.format(calibration_values))