Write a program which will ask the user to enter the initial date of the treatment the weight of the patient and the name of output file and you will create a text file containing the prescriptionImag
date_str = input("Enter the initial date of the treatment (DD/MM): ") weight = int(input("Enter the weight of the patient (in kilograms): ")) output_file = input("Enter the name of the output file: ")
Parse the date string to a datetime object
from datetime import datetime start_date = datetime.strptime(date_str, "%d/%m")
Define the decreasing dose protocol
protocol = [70, 65, 60, 55, 50, 45, 40, 35, 30, 27.5, 25.0, 22.5, 20.0, 17.5, 15.0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] dates = [start_date.replace(day=day) for day in range(start_date.day, 31)] + [start_date.replace(month=start_date.month+1, day=day) for day in range(1, 30)]
Create the prescription text
prescription = "CORTANCYL : Decreasing dose protocol : - {} mg from {} to {}\n".format(protocol[0], start_date.strftime("%d/%m"), dates[0].strftime("%d/%m")) for i in range(1, len(protocol)): prescription += " - {} mg from {} to {}\n".format(protocol[i], dates[i-1].strftime("%d/%m"), dates[i].strftime("%d/%m"))
Write the prescription to the output file
with open(output_file, "w") as file: file.write(prescription)
原文地址: http://www.cveoy.top/t/topic/LJ3 著作权归作者所有。请勿转载和采集!