Inicio
/
Tecnología
/
You Are Developing a A) Non Application for Your School. The Application Must Read and Write Data to a Text File If the Tile Does Not

Problemas

You are developing a A) non application for your school. The application must read and write data to a text file If the tile does not exist, the application must create it. If the file contai must delete the content Which code soyment shoul you use? A open(''localdata'',''''pi t^ast ) B. open(''localdata'',''''') open(''localdata'',''n+'') D open(''localdata'',''r'')

Roztwór

Adrián maestro · Tutor durante 5 años
Weryfikacja ekspertów
4.2 (252 Votos)

Respuesta

To read and write data to a text file, you can use the `open` function in Python. The `open` function takes two arguments: the first is the file name you want to open, and the second is the mode in which you want to open the file. The mode can be 'r' for reading, 'w' for writing, or 'a' for appending.In this case, you want to read and write data to a text file. If the file does not exist, you want to create it. If the file already exists, you want to delete its content. To do this, you can use the 'w' mode with the `open` function. This will create a new file if it does not exist, or overwrite the existing file if it does exist.So, the correct code segment to use is:```pythonopen('localdata', 'w')```This will open the file 'localdata' in write mode. If the file does not exist, it will create it. If the file already exists, it will delete its content and start writing from the beginning.Therefore, the correct answer is B.