Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- def convert_date_text_to_datetime_object(date_as_text):
- "Returns a datetime.date object converted from string 'date_as_text'."
- date_as_list = date_as_text.split(".")
- day, month, year = [int(part) for part in date_as_list]
- return datetime.date(year, month, day)
- def print_file_contents(name_of_the_file):
- "Prints the contents of the file with the name 'name_of_the_file'. Make sure the file is not still open elsewhere before calling this function."
- file = open(name_of_the_file, 'r')
- line = file.readline()
- while line != '':
- print(line, end='')
- line = file.readline()
- file.close()
- def main():
- print("Enter the name of the file to be created for your screen time data:")
- filename = input()
- file = open(filename, 'w')
- print("Enter the start date in format 'DD.MM.YYYY':")
- date_text = input()
- date1 = convert_date_text_to_datetime_object(date_text)
- # Write your code here!
- print("Enter your screen watching time for each day (in minutes) in the format '[Phone minutes] [PC minutes] [TV minutes] [other minutes]'")
- Maarat_summa = 0
- temp = 0
- while True:
- Maara = input("Enter your screen time on {}:".format(date1))
- if Maara == "":
- break
- Maarat = Maara.split(" ")
- date2 = str(date1)
- rivi = date2 + ": " + "/".join(Maarat)
- file.write(rivi + "\n")
- j = 1
- for i in range(0, len(Maarat)):
- Maarat[i] = float(Maarat[i])
- Maarat_summa = Maarat_summa + sum(Maarat)
- temp += 1
- date1 = date1 + datetime.timedelta(days=1)
- # (You can write other functions if you find it of use)
- print("-" * 100)
- print("Screen times saves succesfully in the file '{}'".format(filename))
- print("Saved the screen times of", temp, "days.")
- if temp != 0:
- print("Total screen time from this period is",round(Maarat_summa/60, 1) ,"hours and daily average is",round((Maarat_summa/60)/temp, 1),"hours.")
- print("Let's look inside the file. It looks as follows:")
- print("-" * 100)
- file.close()
- print_file_contents(filename)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement