Print and save the message in the text file to a specified number
Write a program that receives the following inputs:
- Name of a text file with extension
.txt(This is optional input) - The number of times the message should be printed (an integer).
- The text that needs to be printed and stored if there is a file.
The task of the program is to print the entered message to the specified number and if the file name is entered, add the same messages to the end of the file with the suffix.txtSave.
For example, if the inputs are as follows:
name file: example.txt
chap range: 10
text: amirhn.ir
The program output should be as follows:
amirhn.ir
amirhn.ir
amirhn.ir
amirhn.ir
amirhn.ir
amirhn.ir
amirhn.ir
amirhn.ir
amirhn.ir
amirhn.ir
Also textamirhn.ir2 times to the end of the fileexample.txtWill be added.
Note that if the file name is not entered, the program will only print the messages and no file will be created or edited.