Programing Mid Term Review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/71

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

72 Terms

1
New cards

The pass statement generates an error when executed.

False

2
New cards

Which of the following is NOT a logical operator in Python? If, or, and, not?

If

3
New cards

An if statement requires at least one statement in its body.

True

4
New cards

Is there a limit on the number of elif statements that can be used in a chained conditional?

No Limit

5
New cards

The expression "if a and b:" checks if both a and b are True.

True

6
New cards

The "else" statement can exist without a preceding "if" statement.

False

7
New cards

In a chained conditional, what happens if no condition is true and there is no else clause?

 Nothing happens, the program continues to the next statement

8
New cards

The condition in an if-else statement must evaluate to either true or false.

True

9
New cards

If all conditions in a chained conditional are false and there is an else clause, the else clause will execute.

True

10
New cards

Where must the else clause be placed in a chained conditional?

At the end

11
New cards

What does the expression x is y check for in Python?

If x is the same as y

12
New cards

What happens if more than one condition is true in a chained conditional?

Only the first true branch executes

13
New cards

What condition determines whether x is even?

 x % 2 == 0

14
New cards

What will be the output of the following code?

x = 5

if x > 0:

—-) print (‘Positive’)

Positive

15
New cards

The elif statement can be used without a preceding if statement.

False

16
New cards

What does "elif" stand for in Python?

Else If

17
New cards

Given x = 1 and y = 2, what is the value of not (x > y)?

True

18
New cards

What does the “not” operator do?

It makes the Boolean give the opposite True/False Signal

19
New cards

What is the key difference between = and == in Python?

= is used for assignment, while == is used for comparison

20
New cards

Which of the following is NOT a valid comparison operator in Python? =, <=, >= or ! =?

=

21
New cards

There is a limit on the number of statements that can appear in the body of an if statement.

False

22
New cards

The boolean expression after the if statement is called the condition.


True

23
New cards

The expression x > 0 and x < 10 is true when:

 x is both greater than 0 and less than 10

24
New cards
<p><span>What will be the output of the following code if x = 5 and y = 10?</span></p>

What will be the output of the following code if x = 5 and y = 10?

x is less than y

25
New cards
<p><span>What will happen when the following code is executed if phone_balance is 3 and bank_balance is 50?</span></p>

What will happen when the following code is executed if phone_balance is 3 and bank_balance is 50?

 phone_balance will be 13 and bank_balance will be reduced by 10

26
New cards

An else clause is required in every chained conditional

Fasle

27
New cards
term image

x = y

28
New cards

What does the operator != check for?


If two values are not equal

29
New cards

What character must end the if statement header line?

Colon (:)

30
New cards

Which operator is used to check if two values are equal in Python?


==

31
New cards

In a chained conditional, the conditions are checked from top to bottom in the order they appear

True

32
New cards

Which of the following is a text data type in Python? Bool, Int, Str or Float

Str

33
New cards
term image

Hello John

34
New cards
term image

['John', 'Harv', 'Union']

35
New cards
term image

3

36
New cards

Given the variable x = ("apple", "banana", "cherry"), what is the data type of x

Tuple

37
New cards
term image

True

38
New cards
term image

1

39
New cards
term image

Value: 3.33, Type: Float

40
New cards

A variable name must start with a 

Letter or  Underscore character

41
New cards

Given the variable x = ["apple", "banana", "cherry"], what is the data type of x

List

42
New cards
term image

6

43
New cards
term image

HELLO,JOHN!

44
New cards

Variables that are created outside of a function  are known as 

Global Variables

45
New cards

Which of the following statements about tuples in Python is true?

Tuple items are indexed, starting with index 0 for the first item.

46
New cards
term image

3345

47
New cards
term image

8

apple

48
New cards
term image

True

49
New cards

If you create a variable with the same name inside a function, this variable will be:

Local Variable

50
New cards
term image

25Tiger

51
New cards

Which of the following data types is used to represent True or False values in Python? List, Int, Bool or Str?

Bool

52
New cards

Variable names are case-sensitive.

True

53
New cards
term image

False

54
New cards

Which of the following is a numeric data type in Python? Range, Tuple, List or Float?

Float

55
New cards
term image

8

56
New cards
term image

33Tiger

57
New cards

What will happen if you define a function with the same name twice in Python?

The second function definition will overwrite the first one.

58
New cards

Which of the following best describes a function parameter?

It terminates the function,  It defines the name of the function,
It provides a value for the function to process, or  It returns a value from the function?

It provides a value for the function to process.

59
New cards

It provides a value for the function to process. def myFunc():, func myFunc():, def myFunc;, function myFunc():?

def myFunc():

60
New cards

Which of the following statements is true about Python functions?

Function names cannot start with an underscore _ , A function must always have at least one argument, Functions cannot call themselves, or A function can return multiple values?

A function can return multiple values.

61
New cards

What will be the result of bool(1) in Python?

True

62
New cards

What is the Boolean result of 5 > 3 and 10 < 20?

True

63
New cards

What is a correct Python List method used to return the number of elements in a list?

len()

64
New cards

Which of the following is not a valid function call in Python? myFunc[10, 20] ,
myFunc("hello") , myFunc() , myFunc(10, 20)


myFunc[10, 20]
 

65
New cards

Which statement is used to exit a function and return a value?

return

66
New cards

What is the return type of a function that does not return any value?

none

67
New cards

What is the purpose of the type keyword in Python?

It returns the data type of a given variable or value.

68
New cards

Which of the following statements will evaluate to False? bool(0), bool([]), bool(““) or all the above?

All of the above

69
New cards

What is the correct keyword for defining functions in Python?

def

70
New cards

Which of the following represents the Boolean values in Python?

1,0

True, False

true, false

1,0 and True, False

71
New cards

What is recursion in functions?

A function that calls itself

72
New cards

Which of the following is not a valid Boolean expression in Python?

5 == 5

5 === 5
True and False
10 <= 20

5 === 5