2.2.3 Additional programming techniques 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
9
Q

What is an array?

A
  • A set of values that are all stored under one identifier (name)
  • eg. values = [10,15,30,40,42,35]
    0 1 2 3 4 5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does index mean?

A

The position where values sit in the array (0 index array)

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

What is an example of an array?
Values = [10,15,30,40,42,35]

A

print (values[0]) = 10
print(values[3]) = 40
print(values[0:3]) = 10,15,30,40

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

How do you print all the numbers in an array?

A

for i in value:
print(i)
or:
for i in range (len(value)):
print(value[i])

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

What is Libraries/Modules?

A

Built in function that can be controlled to do a task

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

How do you do a random generator?

A

import random (need to import random)
rdn =random.randint(1,10) -> between the 2 values

can call ‘rdn’ whatever you want
randint = random integer

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

What is a subroutine?

A

A small block of code that is part of a big code and can be called to perform a task

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

What is a function?

A

A subroutine that will perform a value back to the program

17
Q

What is a procedure?

A

A subroutine that will not return a value back to the program

18
Q

What is a parameter?

A

Value being passed into a subroutine

19
Q

How do you code a function?

A

Function(def) add(num1,num2):
ans = num1+num2
return(ans)
output = add(15,6)
print(output)

20
Q

How do you code an area of a rectangle as a function?

A

Function area_rec (length,width):
area=(leangth*width)
return(area)
output=area_rec(5,6)
print(output)

21
Q

How do you code a procedure?

A

Procedure(def) add(num1,num2):
ans=num1+num2
print(ans)

22
Q

What is an SQL?

A
  • Structured Query Language
  • Used with databases - > question and return answers from a database
23
Q

What is Field?

A
  • A single piece data to be collected in a database
24
Q

What is Record?

A
  • A collection of fields
25
Q

What is a Table?

A
  • A collection of records (name)
26
Q

What is Select?

A
  • Select the field that you want to return
27
Q

What is From?

A
  • The name of the Table
28
Q

What is Where?

A
  • The condition that you are looking for
29
Q

How do you do a SQL where you return the title and id of a movie which is under 100 minutes long?

A

Select title, Id
from movie
where length_minutes>100

30
Q

What is a wildcard?

A
  • Shortcut to return data in a database
31
Q

What are the 2 wildcards?

A
  • *
  • Like “%”
32
Q

What is (*)?

A
  • Return every field in the database
33
Q

What are some examples of (*)?

A

Select *
from movies
where year == 1995

Select *
from movies
where year >2000 and length_minutes<100

34
Q

What is Like “%”?

A
  • Allows you to return content of a field -> only used in the where condition
35
Q

What are some examples of Like “%”?

A

select director
from movies
where director like “B%”

select title
from movies
where title like “%e”

select title
from movies
where title like “%i%”