2.2.3 Additional programming techniques Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is File Handling?

A

File Handling is a way of storing information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the code to open a file?

A

file = open (“document.txt” , “w”)

file - keyword, assign to operation
open - reserve word to open a document
document - document name
w - operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does w, a and r mean?

A

w - write
a - append
r - read

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the code so it will write your name and age into the file?

A

file.write (name)
file.write (age)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the code to close the document?

A

file.close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What can you not write into a text file?

A

int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Ask 10 students to enter their preferred meal for parents evening

A

for i in range (10):
name = str(input(“What is your name?”))
meal = str(input(“Do you want rice, chicken, pasta or meatballs?”))
file = open(“meal.txt” , “a”)
file.write (name + “,”)
file.write (meal)
file.write (“\n”)
file.close ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does file.write (“\n”) mean?

A

It means new line and you have to apply it to the end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly