python code Flashcards

1
Q

print a message

A

print(‘hello, world’)

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

print multiple values (of different types)

A

ndays=365

print(‘there are’,ndays,’in a year’)

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

asking the user for a string

A

name=input(‘what is your name?’)

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

asking the user for a whole number (integer)

A

num=int(input(‘enter a number’))

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

creating a variable

A

celsius=25

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

using a variable

A

celcius*9/5+32

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

powers

2 to the power of 8

A

2**8

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

decide to run a block (or not)

A

x=3
if x==3:
print(‘x is 3’)

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

decide between two blocks

A
mark=80
if mark>=50:
    print('pass')
else:
    print('fail')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

decide between many blocks

A
mark=80
if mark>= 65:
    print('credit')
elif mark>=50:
   print('pass')
else:
    print('fail')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

equal

A

==

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

not equal

A

!=

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

less than/greater than

A

< / >

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

less than or equal to/greater than or equal to

A

<= / >=

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

repeat a block 10 times

A

for i in range(10):

print(i)

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

sum the numbers 0 to 9

A

total=0
for i in range(10):
total=total+1
print(total)

17
Q

count from 0 to 9

A

range(10)

18
Q

count from 1 to 10

A

range(1,11)

19
Q

count from 10 down to 1

A

range(10,0,-1)

20
Q

count 2 at a time to 10

A

range(0,11,2)