mirror of
https://github.com/JonasunderscoreJones/turbo-octo-potato.git
synced 2025-10-25 19:19:19 +02:00
first dump I could find from my laptop
This commit is contained in:
parent
8d949a52b0
commit
034419b9a5
5 changed files with 310 additions and 0 deletions
38
linesum.py
Normal file
38
linesum.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
def convert_time_to_seconds(time_str):
|
||||
# Split the time string into hours, minutes, and seconds
|
||||
time_parts = time_str.split(':')
|
||||
print(time_parts)
|
||||
# Convert each part to an integer
|
||||
minutes = int(time_parts[0])
|
||||
seconds = int(time_parts[1])
|
||||
|
||||
# Calculate the total time in seconds
|
||||
total_seconds = minutes * 60 + seconds
|
||||
|
||||
return total_seconds
|
||||
|
||||
|
||||
input_file = 'data.txt'
|
||||
total_product = 0
|
||||
|
||||
with open(input_file, 'r') as file:
|
||||
for line in file:
|
||||
line_parts = line.strip().split(':::')
|
||||
print(line_parts)
|
||||
|
||||
# Extract the relevant information
|
||||
avg_track_length = line_parts[6]
|
||||
play_count = int(line_parts[3])
|
||||
|
||||
if avg_track_length == 'NaN:NaN':
|
||||
# Use 3 minutes and 30 seconds (3:30) as the default track length
|
||||
track_length_seconds = convert_time_to_seconds('0:03:30')
|
||||
else:
|
||||
# Convert average track length to seconds
|
||||
track_length_seconds = convert_time_to_seconds(avg_track_length)
|
||||
|
||||
# Calculate the product and add it to the total
|
||||
product = track_length_seconds * play_count
|
||||
total_product += product
|
||||
|
||||
print(f"Sum of (Average Track Length * Play Count): {total_product}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue