Answer:
Following are the code to this question:
with open(filename,"w+") as file: #use an open method that open file in w+ mode
file.write(comments)#use write method that inputs the value in the file
file.close()#closing the file
import os#import package os for file
filesize = os.path.getsize(filename)#defining a variable filesize that uses the getsize method to calculate its size.
Explanation:
Following are the full program to this question:
def create_python_script(filename):#defining method create_python_script that accept filename variable as the parameter
comments = "# Start of a new Python program"#defining a string varaible comments that holds string value
with open(filename,"w+") as file: #use an open method that open file in w+ mode
file.write(comments)#use write method that inputs the value in the file
file.close()#closing the file
import os#import package os for file
filesize = os.path.getsize(filename)#defining a variable filesize that uses the getsize method to calculate its size.
return filesize#return filesize value
print(create_python_script("program.py"))#use print method that call create_python_script and print its return value
Output:
please find program file and its output.
Program description:
In the above-given program, a method "create_python_script" is declared that accept the "filename" as the parameter, inside the method a comments string variable is declared, that holds string value and define an open method to open "program.py" file and assign the string value in the file.
In the next line, the "getsize" method is defined, which counts string value in digits and returns its value and use the print method to call the "create_python_script" with parameter a print its value.