Информатика, вопрос задал rahatmarat76 , 2 года назад

Write a Python program that asks user for name of the file and text that file should contain. Create a text file with given name and fill it with text that entered by user.
Input:

Enter a file name: sample
Enter a text of the file: This file was created at informatics lesson by using
Python programming language.

Ответы на вопрос

Ответил maxum000
1

Code:

name = input("Enter a file name: ") + ".txt"

text = input("Enter a text of the file: ")

with open(name, "w") as file:

   file.write(text)

Output:

Enter a file name: abc                                                                                                        

Enter a text of the file: 12345

abc.txt file is created with the text: 12345

Новые вопросы