Functions, Logic, and Conditionals Flashcards

1
Q

What is “def”

A

This command allows you to define a function

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

What is a function made up of? How do they work?

A

A function has a header and a body. The header contains the function, the body contains the computations in the function. A function takes inputs, computes them as defined, and returns an output. Functions CAN contain (or “call”) other functions.

Eg. 
# converts fahrenheit to celsius
def fahrenheit2celsius(fahrenheit):
    celsius = (5.0 / 9) * (fahrenheit - 32)
    return celsius
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the most common error made in building a function, which will return a value of “None”

A

Forgot to include a “return” statement in the bottom of the function body.

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

In the expression “6 + 7 % 5”, which operator is evaluated first (ie. which has higher precedence)?

A

% is evaluated first, so parentheses needed around anything it applies to.

Eg. (6 + 7) % 5

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

What does the “import” statement do in Python?

A

“import” loads the functions of an external module for use.

Eg. import “math”

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

Boolean Expressions NOT, AND, and OR. What makes each true?

A

All may be true or false.
NOT is true if x is false.
AND is true if x and y are true
OR is true if x or y is true

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

Comparison operators? (six)

A
  1. > greater than
  2. < less than
    3, >= greater or equal to
  3. <= less or equal to
  4. == equal to
  5. != not equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Conditional statements? (Three)

A
"If" = If value is true, then perform this action
"Elif" = if the value is true but another condition is not met, then do perform a different action
"Else" = if value is false, then perform this action
How well did you know this?
1
Not at all
2
3
4
5
Perfectly