Question

In: Computer Science

I don't know which one is wrong. Can you please check. Thank you QUESTION 1 In...

I don't know which one is wrong. Can you please check.

Thank you

QUESTION 1

  1. In the following code, how many and which functions have been defined/declared?

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    1 function: powerNum

    1 function: powerNum

    3 functions: powerNum, and main is defined/declared twice.

    2 functions: powerNum and main

QUESTION 2

  1. In the following code, which of the variable(s) is (are) considered as global variable(s):

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    p and power

    pNum

    p

    power

    n

QUESTION 3

  1. In the following code, which line of code is returning the value for function powerNum?

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    def powerNum(power):

    print ("Power of the number you entered is", powerNum (p))

    return pNum

    pNum = n ** power

QUESTION 4

  1. In the following code, which of the variable(s) is (are) considered as parameter variable(s):

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    n

    pNum

    p and power

    p

    power

QUESTION 5

  1. After learning about the issues with global variables, Amita took the old code with global variables in cell A and re-wrote without global variables. Based on the partial code done in the cell below, what changes, if any, need to be made to the code in cell-B below?

    cell-A: Old code with global variables cell-B: Partial new code without global variables

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    def powerNum(power):

    pNum = n ** power

    return pNum

    def main():

    n = int(input("Enter a number whose power you want to calculate: "))

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    We need to just change powerNum function to accept two parameters: one for power value and one for the number as below

    def powerNum(power, n):

    No changes need to be made to main or powerNum functions

    Yes, powerNum should now be defined with two parameters: one for power value and one for the number as below

    def powerNum(power, n):

    Also we will need to change how the function is called in main function as below:

    powerNum(p,n)

    We need to just pass the additional argument when the powerNum function is called in main function as below:

    powerNum(p,n)

QUESTION 6

  1. In the following code, which line of code is calling or invoking function powerNum?

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    return pNum

    def powerNum(power):

    pNum = n ** power

    print ("Power of the number you entered is", powerNum (p))

QUESTION 7

  1. In the following code, which line of code is defining or declaring function powerNum?

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    def powerNum(power):

    return pNum

    pNum = n ** power

    print ("Power of the number you entered is", powerNum (p))

QUESTION 8

  1. In the following code, which of the variable(s) is(are) considered as argument(s):

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    p and power

    n

    power

    p

    pNum

QUESTION 9

  1. In python, how can you pass arguments to a function?

    by keyword arguments only and can be in any order

    default is by position but you can also pass by keyword arguments as in the case below:

    show_interest (rate=0.01, periods=10, principal=10000.0)

    by position only and they must be passed in the same order in which they are defined in the function header

    by position only and they can be passed in any order irrespective of how are they are defined

QUESTION 10

  1. In the following code, in which order do the lines of code get executed?

    def powerNum(power):

    pNum = n ** power

    return pNum

    n = int(input("Enter a number whose power you want to calculate: "))

    def main():

    p = int(input("Enter the power number: "))

    print ("Power of the number you entered is", powerNum (p))

    main()

    getting input n from the user >>  calling main function >> calling powerNum function >> ending in powerNum function

    calling powerNum function >>  getting input n from the user >>  calling main function

    getting input n from the user >> calling main function >> calling powerNum function >> returning back to main function from powerNum function

Solutions

Expert Solution

Answer 1:-

In this question 2 function were defined/declaired, one is 'main' and other one is 'powerNum', so correct option is,

2 functions: powerNum and main

Answer 2:-

Variable 'n' doesn't belong to any function scope, it is defined outside any function. Hence it is global variable, so correct option is,

n

Answer 3:-

"return pNum" statement is returning value from "powerNum" function

Answer 4:-

Variables present in function signature is called function parameters, so correct option is,

power

Answer 5:-

Since there is no local variable with name 'n', so there won't be any issue, correct option is,

No changes need to be made to main or powerNum functions

Answer 6:-

Function call contains function names followed by paranthesis, so correct option is,

print ("Power of the number you entered is", powerNum (p))

Answer 7:-

Function declairation/defination starts with "def" keyword, so correct option is,

def powerNum(power)

Answer 8:-

Variables that are written inside the paranthesis during function call are called function arguments, correct option is,

p

Answer 9:-

default is by position but you can also pass by keyword arguments as in the case below:

show_interest (rate=0.01, periods=10, principal=10000.0)

Answer 10:-

getting input n from the user >> calling main function >> calling powerNum function >> returning back to main function from powerNum function


Related Solutions

Can you please check my answers and if I am wrong correct me. Thank you! A....
Can you please check my answers and if I am wrong correct me. Thank you! A. In today's interconnected world, many central banks communicate regularly and frequently with the public about the state of the economy, the economic outlook, and the likely future course of monetary policy. Communication about the likely future course of monetary policy is known as "forward guidance.". If the central bank increases the reserve ratio, as the market has perfectly expected, which of the following will...
FOR #4 A & B I don't know if I did it correctly.....Please check & the...
FOR #4 A & B I don't know if I did it correctly.....Please check & the other questions I'm having a heard time on. Thanks! A. You have been given a tube of E. coli. You are asked to make 1 mL total volume of 10-1 dilution of the bacterial culture. Explain how you would do this. Show all necessary calculations. ____ ml cells   +    _____ ml water    = 1 ml    (total volume) V1 D1 X V2 D2 1 mL...
Can someone please explain these problems, I don't understand, please and thank you!! The patients in...
Can someone please explain these problems, I don't understand, please and thank you!! The patients in the Digoxin trial dataset can be considered a population of people suffering from heart failure. These patients were examined before the drug trial began, and their heart rate and blood pressure were recorded. The mean and standard deviation of the variables are listed below. Each variable follows a normal distribution. Heart rate (beats/min)                          μ = 78.8            σ = 12.66 Systolic blood pressure (mmHg)             μ...
4 of these questions are wrong. I need to know which question I got wrong because...
4 of these questions are wrong. I need to know which question I got wrong because I am not sure. During the early and middle twentieth century, there was a sharp increase in human birth rate. a sharp decrease in human death rate. (both) (neither) True/False: If you ask a population ecologist, all the individuals in a population belong to the same species. : True A single population might exist in multiple territories that do not overlap, with no migration...
ANSWER ALL 11 QUESTIONS PLEASE DON'T !!! ANSWER IF YOU DON'T KNOW ALL THE ANSWERS THANK...
ANSWER ALL 11 QUESTIONS PLEASE DON'T !!! ANSWER IF YOU DON'T KNOW ALL THE ANSWERS THANK YOU. 1. What things affect airflow and which one is the most important? 2. Explain how an asthma attack could create a life-threatening condition? 3. Explain how emphysema is associated with expiratory flow limitation and its consequence on the person’s health 4. What are the muscles of inspiration? 5. What role do these muscles perform? 6. What are the primary sources of resistance for...
Can someone please check to see if these are right? If not please explain thank you!...
Can someone please check to see if these are right? If not please explain thank you! Convert the following decimal numbers to their binary-octet equivalent. 114 = 1110010 254 =11111110 229 =11100101 66 = 01000010 7 =00000111 255 =11111111 192 =11000000
HI, I hope you are doing well. I really don't understand this question and don't know...
HI, I hope you are doing well. I really don't understand this question and don't know how to solve it at all because I am completely new to this c++ programming. can you please explain each line of code with long and clear comments? please think of me as someone who doesn't know to code at all. and I want this code to be written in c++ thank you very much and I will make sure to leave thumbs up....
Please type the answer for i can copy it. Thank you very much. -Question 1 Respond...
Please type the answer for i can copy it. Thank you very much. -Question 1 Respond to the following in a minimum of 175 words: Read the following pseudocode class definitions: Class Plant Public Module message() Display "I'm a plant." End Module End Class Class Tree Extends Plant Public Module message() Display "I'm a tree." End Module End Class -Question 2 Given these class definitions, determine what the following pseudocode will display: Declare Plant p Set p = New Tree()...
Please type answer for i can copy it. Thank you very much. -Question 1 What is...
Please type answer for i can copy it. Thank you very much. -Question 1 What is a polymorphism ? -Question 2 Can you start an algorithm in pseudo code? language is in (OOP) object oriented programming
I posted this question before too but answer was wrong can you please make sure the...
I posted this question before too but answer was wrong can you please make sure the answer is right Required information [The following information applies to the questions displayed below.] In 2018, the Westgate Construction Company entered into a contract to construct a road for Santa Clara County for $10,000,000. The road was completed in 2020. Information related to the contract is as follows: 2018 2019 2020 Cost incurred during the year $ 2,204,000 $ 3,192,000 $ 2,424,400 Estimated costs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT