Intro Flashcards
how to set up a string
( )
what is a string
anything in the ( )
what is a variable and how do we asing a variable
If there is a greeting we want to present, a date we need to reuse, or a user ID we need to remember we can create a variable which can store a value. In Python, we assign variables by using the equals sign (=).
How to set up a variable and print
e.g lunch=”toast”
print(“lunch”)
what is a syntax error
SyntaxError means there is something wrong with the way your program is written — punctuation that does not belong, a command where it is not expected, or a missing parenthesis can all trigger a SyntaxError.
What is a name error
A NameError occurs when the Python interpreter sees a word it does not recognize. Code that contains something that looks like a variable but was never defined will throw a NameError.
what is a int
Whole number
what is a float
decimal number you cana define an int and float as variables
what is a literal number
We call the number 3 here a literal, meaning it’s actually the number 3 and not a variable with the number 3 assigned to it.
how to set a varible using number
e.g rating = 4.5.
(dosn’t need strings)
what are the maths symbols you can use in python
multiplication, and division with +, -, *, and /.
e.g
Prints “500”
print(573 - 74 + 1)
Prints “50”
print(25 * 2)
Prints “2.0”
print(10 / 5)
how can Two variables can be added together that are assigned numbers
coffee_price = 1.50
number_of_coffees = 4
Prints “6.0”
print(coffee_price * number_of_coffees)
# Prints “1.5”
print(coffee_price)
# Prints “4”
print(number_of_coffees)
Performing arithmetic on variables does not change the variable — you can only update a variable using the = sign.
What is a exponent
the power of
what is a modulo operator
The modulo operator is indicated by % and gives the remainder of a division calculation. If the two numbers are divisible, then the result of the modulo operation will be 0.
Prints 4 because 29 / 5 is 5 with a remainder of 4
print(29 % 5)
example of modulo
print(3 % 3) # Prints 0
print(4 % 3) # Prints 1
print(5 % 3) # Prints 2
print(6 % 3) # Prints 0
print(7 % 3) # Prints 1
acts as a clock it will always reset
In each of these modulo operations, 3 is the divisor. Since 3 / 3 equals 1 with no remainder, the result of the first modulo operation is 0. Note that as the dividend increases by 1, the remainder also increases by 1, until we reach the next number that is evenly divisible by 3 — this creates a pattern that repeats contiuously as the dividend increases by 1!