Code Example 4-4   def multiply(num1, num2):     product = num1 * num2     result = add(product, product)     return result   def add(x, y):     z = x + y     return z   def main():     num1 = 4     num2 = 3     answer = multiply(num1, num2)     print("The answer is", answer)       main()         B.  Refer to Code Example 4-4: What values are in x and y after the code runs? a. 4, 3 c. 12, 12 b. 5, 6 d. 24, 24           C.  Refer to Code Example 4-4: What is the value of result? a. 48 c. 96 b. 24 d. 12              D.  When writing data into a file: file1 = open (“writehere.txt” , ”w”) , if writehere.txt does not exist: a. the program crashes a. A new file named writehere.txt is created b. an exception is thrown but the program doesn’t crash b. A new file names writehere.txt is created with default data.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section: Chapter Questions
Problem 7PP
icon
Related questions
Question

PYTHON

QUESTION 2 MULTIPLE CHOICE

A.    Refer to Code Example 4-1: What is the scope of the variable named s ?

a.

global

b.

local

c.

global in main() but local in get_username()

d.

local in main() but global in get_username()

 

 

Code Example 4-4

 

def multiply(num1, num2):

    product = num1 * num2

    result = add(product, product)

    return result

 

def add(x, y):

    z = x + y

    return z

 

def main():

    num1 = 4

    num2 = 3

    answer = multiply(num1, num2)

    print("The answer is", answer)

 

    main()

 

      B.  Refer to Code Example 4-4: What values are in x and y after the code runs?

a.

4, 3

c.

12, 12

b.

5, 6

d.

24, 24

 

 

      C.  Refer to Code Example 4-4: What is the value of result?

a.

48

c.

96

b.

24

d.

12

 

    

      D.  When writing data into a file: file1 = open (“writehere.txt” , ”w”) , if writehere.txt does not exist:

a.

the program crashes

a.

A new file named writehere.txt is created

b.

an exception is thrown but the program doesn’t crash

b.

A new file names writehere.txt is created with default data.

 

 

Code Example 5-4

 

with open("members.txt") as file:

    members = file.readlines();

    print(members[0], end="")

    print(members[1])

 

E.  Refer to Code Example 5-4 , it shows:

a.

How to read a list into file

c.

How to read the first and second chars into a file

b.

How to read file into a list

d.

How to read a file into a list with \n

 

Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Computational Systems
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++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning