Python Programming Code Flashcards

1
Q

for i in word:
print(i)

A

display each character in a string called word on separate lines

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

for i in range ( 1, 10, 2)

A

displays
1, 3, 5, 7, 9
starting number: 1
end number: 10
arithmetic: 2

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

for i in range( 1, 10)
print i

A

displays
1, 2, 3, 4, 5, 6, 7, 8, 9, 10

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

==

A

equal to

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

!=

A

not equal to

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

>

A

greater than

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

<

A

less than

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

> =

A

greater than or equal to

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

<=

A

less than or equal to

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

and

A

both conditions must be met

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

or

A

either condition must be met

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

text = str.lower(text)

A

changes the text to lower case

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

len(word)

A

finds the length of the variable word

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

word.upper()

A

changes the string into upper case

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

word.lower()

A

changes the string into lowercase

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

world.title()

A

changes a phrase so that every word has a capital letter at the beginning, with the rest of the letters in the word in lower case

17
Q

print(word.capitalize())

A

displays the variable, word, so that the first word has a capital letter

18
Q

name = firstname+surname

A

joins together without a space between them, CALLED CONCATENATION

displays johnsingleton

19
Q

text = “oh nelly”
print(text.strip(“ “))

A

removes extra characters from the start and the end (spaces)

20
Q

print(“Hello World”[7:10])

A

-each letter of hello world is assigned to an index number position, starting from zero
-it would display positions 7, 8 and 9, which would print “orl”

21
Q

**

A

to the power of

22
Q

print(round(num,2))

A

displays a number rounded to 2dp

23
Q

maths.sqrt(num)

A

square roots the value of the variable num

(must have import math at the beginning of code)

24
Q

num = float(input(“Enter number: “))

A

allows numbers with a decimal point dividing the integer and fraction part

25
Q

x / / y

A

whole number division

26
Q

math.pi

A

displays pi to 15 dp

27
Q

x % y

A

finds the remainder

28
Q

import random

A

must be at the start of the program for randomising function to work

29
Q

num = random.randint(0,9)

A

selects a random whole number between 0 and 9

30
Q

num = random.randrange(0,100,5)

A

picks a random number between the numbers 0 and 100, going up in 5s

31
Q

import random
num = random.random()
print(num)

A

prints a floating point number between 0 and 1

32
Q

num = random.randint(0,1000)

A

prints a random number between 0 and 1000

33
Q

color = random.choice([“red”, “black”, “green”])

A

prints a random colour from the options

numerical values in the list do not require speech marks

34
Q

Tuple

A

-cannot change after it is defined
-data cannot be altered while the program is running

35
Q

List

A

-can be changed while the program is running
-position of items can change and index numbers change

36
Q

dictionary

A

-contents can be changed while the program is running
-index will not change if other rows of data are added or deleted

37
Q
A