Question

In: Computer Science

def main():     print('This program determines whether you have hypertension.')     systolic_pressure = float(input('Enter your systolic...

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

Solutions

Expert Solution

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}


Related Solutions

Python file def calci(): grade = float(input("Enter your grade:")) while (grade <= 4): if (grade >=...
Python file def calci(): grade = float(input("Enter your grade:")) while (grade <= 4): if (grade >= 0.00 and grade <= 0.67): print("F") break elif (grade >= 0.67 and grade <= 0.99): print("D-") break elif (grade >= 1.00 and grade <= 1.32): print("D") break elif (grade >= 1.33 and grade <= 1.66): print("D+") break elif (grade >= 1.67 and grade <= 1.99): print("C-") break elif (grade >= 2.00 and grade <= 2.32): print("C") break elif (grade >= 2.33 and grade <=...
Write a program that determines whether an input string is a palindrome; that is, whether it...
Write a program that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. In Pseudocode please
def main(): phrase = input('Enter a phrase: ') # take a phrase from user acronym =...
def main(): phrase = input('Enter a phrase: ') # take a phrase from user acronym = '' # initialize empty acronym for word in phrase.split(): # for each word in phrase acronym += word[0].upper() # add uppercase version of first letter to acronym print('Acronym for ' + phrase + ' is ' + acronym) # print results main() The program should then open the input file, treat whatever is on each line as a phrase and make its acronym using...
You are on a diet and you are writing a javascript program that determines whether or...
You are on a diet and you are writing a javascript program that determines whether or not you can treat yourself to an ice cream. Your program takes as input: 1. Number of calories you have taken so far that day. 2. Number of calories you are expecting to take later on that day (excluding the potential ice cream) 3. Number of calories you have burnt (or are expecting to burn) with exercise that day. 4. What is your goal...
using python 3 1. Two-line input: print a prompt (e.g Enter your first name) and then...
using python 3 1. Two-line input: print a prompt (e.g Enter your first name) and then assign the input to a variable print ("Enter your first name")# the word prompt is the message the user should see firstName = input() print (firstName)
You have to write a program that will read an array from a file and print...
You have to write a program that will read an array from a file and print if the numbers in the file are right truncatable primes. A right truncatable prime is a prime number, where if you truncate any numbers from the right, the resulting number is still prime. For example, 3797 is a truncatable prime number number because 3797, 379, 37, and 3 are all primes. Input-Output format: Your program will take the file name as input. The first...
You have to write a program that will read an array from a file and print...
You have to write a program that will read an array from a file and print if the numbers in the file are right truncatable primes. A right truncatable prime is a prime number, where if you truncate any numbers from the right, the resulting number is still prime. For example, 3797 is a truncatable prime number number because 3797, 379, 37, and 3 are all primes. Input-Output format: Your program will take the file name as input. The first...
You have to write a program that computes the area of a triangle. Input consists of...
You have to write a program that computes the area of a triangle. Input consists of the three points that represent the vertices of the triangle. Points are represented as Cartesian units i.e. X,Y coordinates as in (3,5). Output must be the three points, the three distances between vertices, and the area of the triangle formed by these points. The program must read the coordinates of each point, compute the distances between each pair of them and print these values....
Write a program to print the number of class assignments you have done so far, the...
Write a program to print the number of class assignments you have done so far, the total grades, and average grade. Prompt a 0 input to end the program. Java Using while statements in the lecture this was provided. Wording confused me, Total grade is sum of all grades.
JAVA script! You will write a program that will input the nationalities of your favorite types...
JAVA script! You will write a program that will input the nationalities of your favorite types of food, examples, and prices of some of your favorite food. You will save a type of food, two examples of that type of food, the price of each of those two examples, and a total price of both together. You must input your own types, examples, and prices, but check a sample run below. You must use the concepts and statements that we...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT