Question 1   Match these function names with the most accurate statement about them. Function names:  a   2nd_name    getName    input    Calculate_total    user_name    statements:    This is a good function name.   This name is the same as a Python built-in name (and so should not be used).   This name sounds like a noun/variable.   This name does not use the standard naming convention.   This name does not give enough information about the meaning of the function.   This name is invalid (breaks Python naming rule)    Question 2    Write the result of the expression (as evaluated by Python): int(5.7) // 2   Blank 1 - add your answer    Question 3    Which one of the following is a correct way to get the user to enter their salary and store it in a Python variable?   a) variable = input(float("salary")) b) input = float("salary") c) salary = float(input()) d) float(input("salary))

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 1TF: Mark the following statements as true or false: a. To use a predefined function in a program, you...
icon
Related questions
Question

Answer the following questions and fill and the blanks 

 

Question 1

 

Match these function names with the most accurate statement about them.

Function names: 

a

 

2nd_name 

 

getName 

 

input 

 

Calculate_total 

 

user_name 

 

statements: 

 

This is a good function name.

 

This name is the same as a Python built-in name (and so should not be used).

 

This name sounds like a noun/variable.

 

This name does not use the standard naming convention.

 

This name does not give enough information about the meaning of the function.

 

This name is invalid (breaks Python naming rule) 

 

Question 2 

 

Write the result of the expression (as evaluated by Python):

int(5.7) // 2

 

Blank 1 - add your answer 

 

Question 3 

 

Which one of the following is a correct way to get the user to enter their salary and store it in a Python variable?

 


a) variable = input(float("salary"))


b) input = float("salary")



c) salary = float(input())


d) float(input("salary))

 

Question 4

 

What is wrong with the following code?

 

def main():

      age = get_age()

      print(f"At {age}, you are half-way to {age * 2}")

 

 

def get_age():

      x = int(input("Age: "))

      return x

 

 

main()

 


a) Something is wrong with the f-string in the print function

b) The variable in get_age must be called age, not x

c) The get_age function breaches the Single Responsibility Principle (SRP)

D) None of the above - there are no problems with this code

 

 

Question 5

 

Consider a program that calculates total pay. Which one of the following decision patterns would be the most appropriate choice for the situation where a bonus is applied when the pay is over a certain threshold?

 

a) if, no else

B) if-else

C) if-elif-else

 D) if-elif no else

E) if, if, if...

 

Question 6

 

What is the result of the following expression?

 

float(int(5.7)) ** 2

 


A) 32.49

B) 11.4

C) 10.0

D) 25.0

E) None of the above

 

Question 7 

 

Which one of the following statements about using global variables is False?

 


A) Global variables are defined inside functions and their scope is only within their own functions

B) Global variables can lead to problems and make debugging more difficult

C) Global variables make programs with functions harder to read and understand


D) Global constants are acceptable

 

 

Question 8 

 

Which one of the following is the correct keyword argument to use in Python's print function when you want to change the default value that is printed between (multiple) arguments provided?

 


A) end

B) sep

C) line

D)printline

 

Question 9

 

What is the output of the following code?

 

def main():

      x = do_something(3)

      y = do_something(x)

      print(x + y)

 

def do_something(a):

      x = a - 1

      b = a * 2

      return b

 

main()

 

 

Blank 1 - add your answer 

 

 

Question 10 

 

Consider the following code:

 

import random

 

x = random.randint(1, 10)

y = random.randint(5, 11 * x)

print(y)

 

What is the lowest value that could be printed?

Blank 1 - add your answer 

What is the highest value that could be printed?

Blank 2 - add your answer 

 

 

Question 11

 

Which one of the following is the best name for a function that converts colour values from RGB format to HSV format?

 

A) rgb_hsv

B) RGB_to_HSV

C) convert_colour_formats

D) convert_rgb_to_hsv

 

 

Question 12

 

Consider the following code:

 

import random

print(random.randint(random.randint(1, 10), random.randint(10, 20)))

 

What are the lowest and highest values that could be printed?


A) 1 and 10

B) 1 and 20

C) 10 and 20

D) None of the above

 

Expert Solution
steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning