Statements Flashcards
Write down the seven assignment operators. Know what they do
= \+= -= *= /= %= **=
There is an Acronym describing how operators are ordered. Which one?
PEMDAS
1. parentheses
2. exponents
3. multiplication
4. division
5. addition
6. subtraction.
Assign 1 to 4 variables. Whats the name of the operation?
Chained assignment
~~~
a=b=c=d= 1
~~~
What would this output? a = b = c = d + 10 = 6
- Syntax Error
- Assignment operator expects only one variable to be on the left-hand side of the equation
Give a full example of how to use the input variable
print("What is your name?") his_name = input() Keyboard: "David" print("Your Name is: ", his_name)
Define If statements
- conditional statement
- evaluate an expression
- If true, following code executed
- If false, following code skipped
What is the difference between a statement and expression?
- Statement is a line of code that the interpreter can execute
- Expression is a section of code that the interpreter evaluates to a certain value.
Write down the 6 boolean operators. What do they hold?
They hold a bool
- They hold a Bool
~~~
==
!=
>
>=
<
<=
~~~
Write a if statement asking the user if a player wants jersey number 22 or 24. Print the output
print("We have two choices of jersey numbers for Podolski") print("You decide:") print("22 or 40") jersey_num = input() if int(jersey_num) == 22: print("The Jersey number is 22") elif int(jersey_num) == 40: print("The Jersey number is 40") else: print("Dann nicht")
Do an Elif Statement inputing a number and evaluating if if number is negative, zero or positive and finish with a goodbye.
print("What is your number?: ") num = int(input()) if num < 0: print("Your number is negative") elif num == 0: print("Your number is zero") else: print("Your number is positive") print("Goodbye")
Define what a loop is
- One of the most important and powerful tools for programming
- Repeat the same set of instructions repeatedly until a specified condition is met.
What is a range function and which parameters are used?
- Creates range of numbers based on a set of parameters. Those parameters are as follows:
Start
* optional
Stop
* required
Step
* optional
What does the for loop in a range function? Write down Example
- Lets you loop through all the numbers in set created by range
for x in range(3, 5): print(x) Output: 3 4
Create a range from 5 - 10 with the step parameter set to 2. Whats the output?
for x in range(5, 10, 2): print(x) Output: 5 7 9
Where is the first and last item of index?
- 0
- n-1