Which programming structure is the most appropriate

Assignment Help Python Programming
Reference no: EM132357199

Multiple Choice Practice Questions

Select the best answer.

1. In a Python program, values are stored in:

a. statements
b. expressions
c. variables
d. operators

2. A value that is passed to a function is called:

a. identifier
b. argument
c. statement
d. parameter

3. Pseudocode is:

a. Python code, modified to be suitable for documentation
b. a few general statements about what a program will do
c. a detailed account of an algorithm in English rather than code
d. all comments from a program extracted into documentation

4. A function can send a value back to the method that called it using a(n):

a. operator
b. return statement
c. print statement
d. loop

5. What is the output of the following code?

def main():
x=10
x=calTest(x)
print (x)

def calTest(y):
y = int (y)
y= y*2+2*3/2
return y

main()

a. 5
b. 23
c. 10
d. 26

6. Which of the following would be a legal variable name?

a. class
b. 8th
c. MY_GUI
d. Second-name

7. To use the functions in an external module, a program should use:

a. comment
b. open statement
c. operator
d. import statement

8. In object-oriented programming, a class contains:

a. pseudocode
b. variables and methods
c. methods
d. variables

9. Which programming structure is the most appropriate to describe the statement "When it's cold close the window and the curtains otherwise leave the window and curtains open":

a. if...elif...else
b. while
c. if...else
d. for

10. If you need to re-use a section of code and use it in a number of different places, which is the most appropriate approach to use:

a. while loop
b. for loop
c. if statement
d. a function

11. What is the appropriate statement to call the doCalc() method of an object called thisObj, and capturing the return value into a variable result?

a. doCalc(thisObj, x, result)
b. result = doCalc()
c. result = thisObj.doCalc(x)
d. result = thisObj.doCalc()

12. What is the output of the following code?

def main():
x=5
y=4
x=calTest(x,y)
print (y)

def calTest(y,z):
z = 4
y = int (y)
y= y*z+2*3/2
return y

main()

a. 3
b. 23
c. 13
d. 4

13. What is the output from the following code?

for i in range (-1,9,3):
print (i)

a. 1 4 7
b. 8 7 6 5 4
c. -1 2 5 8
d. -1 2 5

14. What is the output of the following code?

myDict = {2:'cat',4:'chicken',3:'dog',1: 'rabbit'}
print (myDict[3])

a. cat
b. chicken
c. dog
d. rabbit

15. What is the output of the following code?

def main():
x=5
y=3

if x > 5:
x=calTest(x,y)

elif x <= 5:
x =calTest2(x,y)
print (x)

def calTest(y,z):
z = 4
y = int (y)
y= y*z+2*3/2
return y

def calTest2 (a,b):
a = int(a)
b = int(b)
c = a+b-55+102
d = c
c = 5
return c

main()

a. 55
b. 15
c. 5
d. 7

For questions 16 and 17, use the following variable assignment:

myList = [7 , 3 , 2 , 8]

16. What is the output of:

print (myList[2])

a. 2
b. 7
c. 9
d. 3

17. What is the output of:

print (7.0 / 2.0 + 2.0 * myList[2])

a. 11
b. 9.5
c. 7
d. 7.5

18. What is the output of:

x = 10
y = 5
if x > 2 and y < 6:
print (1)

elif x < 3 and y >= 5:
print (2)

elif x >= 3 and y < 5:
print (3)

else:
print (4)

a. 1
b. 2
c. 3
d. 4

19. What is the output from the following code:

def main():
x=5
x = calTest(x)
print (x)

def calTest(y):
y = int (y)
y= y*2+2*3/2

main()

a. 6
b. 13
c. 10
d. 5

20. What is the output from the following:

myString = 'letsDoIt'
print (myString[1:-3])

a. etsD
b. tsDo
c. etsDoI
d. none of the above

Reference no: EM132357199

Questions Cloud

Explain the compression techniques of zero length : Briefly explain the compression techniques of zero length suppression and runlength encoding.
Why the maintenance phase of sdlc : In your own opinion, speculate why the maintenance phase of SDLC is often so much larger than the other phases.
Why do you think the challenge might occur : Emergency Operations Centers (EOCs) are the critical structure for emergency response. EOCs perform six functions in response to an emergency.
Describe an obstacle you could potentially encounter : First, describe an obstacle you could potentially encounter when presenting quantitative information to a wider audience that includes participants.
Which programming structure is the most appropriate : Which programming structure is the most appropriate to describe the statement "When it's cold close the window and the curtains otherwise leave.
Write the code necessary to count number of perfect squares : Write the code necessary to count the number of perfect squares whose value is less than h, starting with 1. Assign the sum you compute to a variable q.
Sustainability - the triple bottom line and business : Sustainability, the Triple bottom line and business - understandings of the themes but also their consideration of the implications for the business sector
Describe the values they store and adhere to python : How to write in an include pseudocode that describes all steps required to solve the problem, and employ variable names.
Amendment always seems to generate a spirited discussion : The 4th Amendment always seems to generate a spirited discussion. It's not surprising given the fact that our 4th Amendment jurisprudence

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd