Intro Flashcards

1
Q

how to set up a string

A

( )

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

what is a string

A

anything in the ( )

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

what is a variable and how do we asing a variable

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to set up a variable and print

A

e.g lunch=”toast”
print(“lunch”)

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

what is a syntax error

A

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.

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

What is a name error

A

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.

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

what is a int

A

Whole number

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

what is a float

A

decimal number you cana define an int and float as variables

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

what is a literal number

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how to set a varible using number

A

e.g rating = 4.5.

(dosn’t need strings)

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

what are the maths symbols you can use in python

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how can Two variables can be added together that are assigned numbers

A

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.

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

What is a exponent

A

the power of

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

what is a modulo operator

A

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)

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

example of modulo

A

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!

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

when is a modulo useful in programming

A

Because of this, the modulo operator is useful in programming when we want to perform an action every nth time something occurs. Imagine you own a small café and would like for every 7th customer to receive a survey. If every customer transaction is numbered in the order they occur, you can determine which customers should receive the survey by calculating <transaction> % 7 — if the result is 0, hand out the survey!</transaction>

17
Q

what does the % does in the modulo

A

The modulo operator is indicated by % and gives the remainder of a division calculation.

18
Q

what is Concatenation

A

The + operator doesn’t just add two numbers, it can also “add” two strings! The process of combining two strings is called string concatenation. Performing string concatenation creates a brand new string comprised of the first string’s contents followed by the second string’s contents (without any added space in-between).

19
Q

what is an example of concatrnation

A

greeting_text = “Hey there!”
question_text = “How are you doing?”
full_text = greeting_text + “” + question_text

Prints “Hey there!How are you doing?”
print(full_text)

20
Q

how to you add a number to a concatenateion

A

using the str( ) function.

e.g birthday_string = “I am “
age = 10
birthday_string_2 = “ years old today!”

full_birthday_string = birthday_string + str(age) + birthday_string_2

Prints “I am 10 years old today!”

print(full_birthday_string)

21
Q

what is plus equals

A

a shorthand for updating variables. When you have a number saved in a variable and want to add to the current value of the variable, you can use the += (plus-equals) operator.

22
Q

what is can example of plus equals

A

number_of_miles_hiked = 12

Then we need to update that variable
# Let’s say we hike another two miles today
number_of_miles_hiked += 2

The new value is the old value
# Plus the number after the plus-equals
print(number_of_miles_hiked)
# Prints 14

23
Q

show example of +=

A

We’re doing a little bit of online shopping and find a pair of new sneakers. Right before we check out, we spot a nice sweater and some fun books we also want to purchase!

Use the += operator to update the total_price to include the prices of nice_sweater and fun_books.

24
Q

what is a multi line string

A

Python strings are very flexible, but if we try to create a string that occupies multiple lines we find ourselves face-to-face with a SyntaxError.

25
Q

example of +=

A

number_of_miles_hiked = 12

number_of_miles_hiked += 2

print(number_of_miles_hiked)
# Prints 14

26
Q

how to set a multi line string

A

Python offers a solution: multi-line strings. By using three quote-marks (“”” or ‘’’) instead of one, we tell the program that the string doesn’t end until the next triple-quote.

27
Q

what is input ( )

A

The input() function requires a prompt message, which it will print out for the user before they enter the new information. For example:

likes_snakes = input(“Do you like snakes? “)

28
Q
A
29
Q
A
30
Q
A