In: Computer Science
In Python
A child is required to use a booster seat in a car until the child is 9 years old, unless the child reaches the height of 59 inches before age 9. Which expression can be used to decide if a child requires a car seat or not?
a. |
if age < 9 or height < 59: |
|
b. |
if age >= 9 or height >= 59: |
|
c. |
if age >= 9 and height >= 59: |
|
d. |
if age <= 9 and height <=59: |
|
e. |
None of the above |
What conditions have to be true to make the following code display "B"?
if color == 'red':
if style < 3:
print('A')
elif style < 5:
print('B')
else:
print('C')
elif color == 'blue':
print('D')
a. |
color is 'blue' and style is 3 |
|
b. |
color is 'red' and style is 6 |
|
c. |
color is 'red' and style is 5 |
|
d. |
color is 'red' and style is 4 |
|
e. |
None of the above |
What conditions have to be true to make the following code display "B"?
if color == 'red':
if style < 3:
print('A')
elif style < 5:
print('B')
else:
print('C')
elif color == 'blue':
print('D')
a. |
color is 'blue' and style is 3 |
|
b. |
color is 'red' and style is 6 |
|
c. |
color is 'red' and style is 5 |
|
d. |
color is 'red' and style is 4 |
|
e. |
None of the above |
Which statement is equivalent to the following assignment?
x -= 2 + y
a. |
x = 2 + y - x |
|
b. |
x = -(2 + y) |
|
c. |
x = x - (2 + y) |
|
d. |
x = x - 2 + y |
|
e. |
None of the above |
Which of the following data values is best represented with a floating point variable?
a. |
The speed of a snail. |
|
b. |
None of the other options |
|
c. |
The number of children in a classroom. |
|
d. |
The number of acorns in a tree. |
|
e. |
The number of pets in a house. |
1) A child requires a car seat when he attains a age of atleast age greater than or equal to 9 and height greater than or equal to 59 .
Answer :
b. |
if age >= 9 and height >= 59: |
2) and 3)
if color == 'red':
if style < 3:
print('A')
elif style < 5:
print('B')
else:
print('C')
elif color == 'blue':
print('D')
In the above code the contents of if statement contains the print('B') which would be executed only when the inner elif condition is reached and style < 5 is true i.e, (style = 4)
style < 5 is true
If the color = 'red' and style = 4 then the above if-else statements prints B to output.
Answer :
d. |
color is 'red' and style is 4 |
4) x -= 2 + y
This statement is decrementing the value of x by (2+y) which is equivalent to x = x - (2+y)
Answer :
c. |
x = x - (2 + y) |
5) floating point Variable is used to store decimal values . Remember that a number is always is a integer.
Answer :
a. |
The speed of a snail. |
speed = distance / time , which means we get a fraction which is a decimal value or floating point