How do you print something
print(“enter code”)
How do you save something as a variable?
x = 30
(X is the variable)
Does indentation for python matter?
Yes, it is important for indicating a block of code.
What is a comment and what symbol is used for it?
It is a way to put something into a code that won’t be read. It starts with a pound sign.
Ex:
# this code prints your name
print(input(“Enter your name”))
How do you input something.
variable = input(“input here”)
How do you input a number?
number = int(input(“enter a number”))
What is the difference between x + 1 and x=x+1
The first adds one to the variable, but the second one actually changes the variable.
how do you find a random number?
import random
#then do this
random.randint()
How do you get a remainder from division with the % operator?
remainder = 10 % 3
print(remainder)
#output = 1
How do if - else blocks work
if the code satisfies a certain criteria something (if) then something will happen and if not (else) then something else will happen
How do you put something to a power in python
powers = pow(3 , 4)
How do you do the square root of something
Import math
math.sqrt(9)
What is the difference between a numeric variable and a text string
Numbers need int, text strings need quotes.
What does the function len() do?
It finds the length of something; a string, or a list item.
What does the function int() do?
output = 9
It rounds a number down to the nearest integer.
int(9.9)
#output = 9
What does the function str() do?
it converts something into a string
Ex:
Str(99)
#output = ‘99’
How do you show addition, subtraction, multiplication and division?
+ , - , * , /
What is an example of an algorithm?
Step by step instructions to do something. An example is a morning routine or a daily schedule.
How do you find the length of a list?
len(thislist)
How do you put something into a list?
bradylist.insert(1,”code”)
How do you remove a list item?
mlist.pop(3)
How do you add something to the end of a list?
mylist.append(“arrested”)
If you wanted to find the 3rd item of a list, what would you do?
itemthree = mylist[2]
What does a while loop do?
Until a certain thing happens, it will run code.
Ex:
while x < 4:
Print(x)
x = x + 1