#Write a function called "write_file" that accepts two
#parameters: a filename and some data that will either
#be an integer or a string to write. The function
#should open the file and write the data to the file.
#
#Hints:
#
# - Don't forget to close the file when you're done!
# - If the data isn't a string already, you may need
# to convert it, depending on the approach you
# choose.
# - Remember, this code has no print statements, so
# when you run it, don't expect to see any output
# on the right! You could add print statements if
# you want a confirmation the code is done running.
# - You can put the variable for the filename in the
# same place where we put text like OutputFile.txt
# in the videos.
# Write a function called "write_file" that accepts two # parameters: a filename and some data that will either # be an integer or a string to write. The function # should open the file and write the data to the file. # # Hints: # # - Don't forget to close the file when you're done! # - If the data isn't a string already, you may need # to convert it, depending on the approach you # choose. # - Remember, this code has no print statements, so # when you run it, don't expect to see any output # on the right! You could add print statements if # you want a confirmation the code is done running. # - You can put the variable for the filename in the # same place where we put text like OutputFile.txt # in the videos. def write_file(filename, data): f = open(filename, 'w') f.write(str(data)) f.close()
Get Answers For Free
Most questions answered within 1 hours.