In: Computer Science
def main():
print('This program determines whether you have hypertension.')
systolic_pressure = float(input('Enter your systolic pressure: '))
diastolic_pressure = float(input('Enter your diastolic pressure: '))
# insert statement here to call the hypertension_tester function
def hypertension_tester(dp, sp):
if sp >= 140 or dp >= 90:
print('You have hypertension')
else:
print('You do not have hypertension')
main()
A person has hypertension if systolic pressure is 140 or above or diastolic pressure is 90 or above. Which of the following statements correctly calls the hypertension_tester function?
A. |
hypertension_tester(diastolic_pressure, systolic_pressure, ) |
|
B. |
hypertension_tester(sp=systolic_pressure, dp=diastolic_pressure) |
|
C. |
Both (A) and (B) are correct |
|
D. |
Both (A) and (B) are incorrect |
def main():
num1 = float(input('Enter a number: '))
num2 = float(input('Enter another number: '))
difference, total = sum_diff(num1, num2)
print('Their total is', total)
print('Their difference is', difference)
# Insert definition of the sum_diff function here
main()
Which of the following definitions of the sum_diff function is correct?
A. |
def sum_diff(x, y): sum = x + y diff = x - y return sum return diff |
|
B. |
def sum_diff(x, y): sum = x + y diff = x - y return diff, sum |
|
C. |
def sum_diff(x, y): sum = x + y diff = x - y |
|
D. |
def sum_diff(x, y): sum = x + y diff = x - y return sum, diff |
my_dict = {21 : 'Amy', 45 : 'Bob', 62 : 'Connie', 57 : 'Dave'}
Which of the following statements will display the string 'Bob'?
A. |
print(my_dict[1]) |
|
B. |
print(my_dict[45]) |
|
C. |
print(my_dict['45']) |
|
D. |
None of the above |
Which of the following statements creates an empty set in Python?
A. |
my_set = ( ) |
|
B. |
my_set = set() |
|
C. |
Both (A) and (B) create an empty set |
|
D. |
None of the above |
Suppose all elements in the set my_set are integers. Which of the following Python program fragments selects all even numbers from my_set and stores them in my_set2?
A. |
my_set2 = {x for x in my_set if x % 2 == 1} |
|
B. |
my_set2 = [x for x in my_set if x % 2 != 0] |
|
C. |
my_set2 = {x for x in my_set if x % 2 == 0} |
|
D. |
none of the above |
1) C Both (A) and (B) are correct
hypertension_tester(diastolic_pressure, systolic_pressure, )
hypertension_tester(sp=systolic_pressure,
dp=diastolic_pressure)
Both are valid
Function calling in python:
def func(x):
print(x)
func(10) #print 10
func(x=10) #print 10
2) B
difference, total = sum_diff(num1, num2)
We are expecting difference first and then total.
So it should return diff, sum
def sum_diff(x, y):
sum = x + y
diff = x - y
return diff, sum
3) B print(my_dict[45])
Bob is the value of key 45, so we can access Bob using
my_dict[45].
And 45 is an integer type in dictionary.
4) B my_set = set()
my_set = ( ) represents an empty tuple
my_set = set() represents an empty set
5) C my_set2 = {x for x in my_set if x % 2 == 0}
A number is said to be even number if it is divisible by 2 i.e.
num%2==0 then num is even else odd.
my_set2 = {x for x in my_set if x % 2 == 0}