python code Flashcards
1
Q
print a message
A
print(‘hello, world’)
2
Q
print multiple values (of different types)
A
ndays=365
print(‘there are’,ndays,’in a year’)
3
Q
asking the user for a string
A
name=input(‘what is your name?’)
4
Q
asking the user for a whole number (integer)
A
num=int(input(‘enter a number’))
5
Q
creating a variable
A
celsius=25
6
Q
using a variable
A
celcius*9/5+32
7
Q
powers
2 to the power of 8
A
2**8
8
Q
decide to run a block (or not)
A
x=3
if x==3:
print(‘x is 3’)
9
Q
decide between two blocks
A
mark=80 if mark>=50: print('pass') else: print('fail')
10
Q
decide between many blocks
A
mark=80 if mark>= 65: print('credit') elif mark>=50: print('pass') else: print('fail')
11
Q
equal
A
==
12
Q
not equal
A
!=
13
Q
less than/greater than
A
< / >
14
Q
less than or equal to/greater than or equal to
A
<= / >=
15
Q
repeat a block 10 times
A
for i in range(10):
print(i)