Programming (Paper 2) Flashcards

(20 cards)

1
Q

how to turn a string from lower case to uppercase

A

print(Variable.upper())

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

how to turn a string from upper case to lower case

A

print(Variable.lower())

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

how to turn a string to have title case

A

print(Variable.title())

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

command to count the number of characters in a string

A

print(len(Variable))

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

how to extract a substring from a large string from a sequence of characters

A

print(Variable[3:5])

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

how to concatenate two or more strings

A

variable = variable1 + variable2

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

how to open a file

A

file = open(“fruit.txt”,”r”)

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

how to close a file

A

file.close()

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

How to read a line in a file

A

file.readline()

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

how to write a line in a file

A

file.write(“oranges”)

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

how to create a new file

A

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

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

how to append a file

A

file = open(“shopping.txt”,”a”)

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

how to perform an SQL query

A

SELECT (what to return)
FROM (specifies the table name to retrieve data from)
WHERE (filters the data based on a specific condition)

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

how to create a 1D array

A

scores = [0]*5
creates an array with 5 elements, each initialised to 0

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

how to create a 2D array

A

players = [[None]*3 for _ in range(3)]
creates a 3x3 2D array with all values set to None

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

how to assign a value to a 2D array

A

players [0][1] = “Holly”
replaces text in row 0, column 1 with “Holly”

17
Q

how to create a populated 2D array

A

players = [[“Rob”,”Paul”,”Hayley”], [10, 5, 8]]

18
Q

how to access a value in a 2D array

A

value = players[2][2]
retrieves the value at row 2, column 2

19
Q

how to create a function

A

def squared(number):
squared = number^2
return squared

20
Q

how to generate a random number

A

import random
number = random.randint(1,10)