Question

In: Computer Science

1. Which of the following is a method that can be called on a list? Group...

1.

Which of the following is a method that can be called on a list?

Group of answer choices

split()

lower()

strip()

All of the above methods can be called on a list

None of the above

2.

Which one of these correctly reads a value from the keyboard into variable x?  

Group of answer choices

input(x)

readline(x)

x = input()

x = readline()

3.

What happens if you run the following code?  

 x = input("Enter a value: ") 
 if x > 50: 
     print("You have entered a value over 50.") 

Group of answer choices

It prints “You have entered a value over 50.” if the user enters 52

It prints whatever the user enters

It does not run because the type of the value x is different than that of 50

It does not run because the value of x is not set when the program starts

4.

Which one of the following statements is NOT true?

Group of answer choices

While loops always increment the iterating variable automatically in each iteration.

A while loop is best for situations when we do not know how many times the statements in the body of the loop need to be executed.

The statements in the body of a for loop must be indented.

Variables initialized in a function have local scope.

A while loop can iterate infinitely (i.e., an infinite loop)

5.

Suppose s is a variable that has been assigned a string, but you don't know exactly what that string is. Consider the expression:  

s.split().strip()  

Group of answer choices

It evaluates to a list where elements are strings with no spaces at all

It evaluates to a string with no leading and no trailing spaces

It produces an error always

It produces an error except when s is the empty string

None of the above

6.

If the variable lst is assigned the list ['apple', 'orange', 'pear', 'plum'], which one of the following statements will cause an error when run?

Group of answer choices

print(lst[-1])

print(lst[0])

print(lst[3])

print(lst[4])

7.

What should ??? be replaced by to make the printed value of n as big as possible?

lst = ["gold", "red", "green",   
       "gray1", "gamboge",   
       "yellow", "teal"]  
n = 0  
for c in lst:  
    if c[1] == ???:  
        n = n + 1  
print(n)  

Group of answer choices

'a'

'e'

'g'

'r'

8.

Select all the Boolean expressions:  

Group of answer choices

8 + 1 = 4

6 == 2 + 3

4 + 2 == 8

‘dog’ == ‘doggy’

True

print("False")

12 > 14

'cat' < 'dog' and 2 > 3

5 = 2 + 4

9.

In a Python program, functions must be called in the same order as they are defined in the ".py" file.

Group of answer choices

True

False

Solutions

Expert Solution

1. answer: None of the Above

2. answer: x = input()

3.answer: It does not run because the type of the value x is different than that of 50

4. answer:

  • While loops always increment the iterating variable automatically in each iteration.
  • A while loop is best for situations when we do not know how many times the statements in the body of the loop need to be executed.

5. answer: It produces an error always

6. answer: print(lst[4])

7. answer: 'e'

8.

6 == 2 + 3

4 + 2 == 8

'dog' == 'doggy'

True

12 > 14

'cat' < 'dog' and 2 > 3


9. answer: FALSE


Related Solutions

The following program creates a linked list which contains 5 links. Add a method called findMax()...
The following program creates a linked list which contains 5 links. Add a method called findMax() to the LinkedList class. The findMax() method must be of type integer, it must search the list and return the maximum value of the number data field. Add the required code to the main() method to call the findMax() method. public class Link { private int number; private Link next; public Link(int x) { number = x; } public void displayLink() { System.out.println("The number...
The following program creates a linked list which contains 5 links. Add a method called findMax()...
The following program creates a linked list which contains 5 links. Add a method called findMax() to the LinkedList class. The findMax() method must be of type integer, it must search the list and return the maximum value of the number data field. Add the required code to the main() method to call the findMax() method. public class Link { private int number; private Link next; public Link(int x) { number = x; } public void displayLink() { System.out.println("The number...
Using python. Produce a method for a linked list that is called FIND , which returns...
Using python. Produce a method for a linked list that is called FIND , which returns the index of a lookup value within the linked list
1. Which of the following is a formal research method? Group of answer choices Looking in...
1. Which of the following is a formal research method? Group of answer choices Looking in company files Brainstorming Investigating primary sources Talking with your boss 2. When should passive voice be used in business writing? Group of answer choices When you want to de-emphasize the action or the recipient of the action Never When you want to conceal the doer of the action When you want to emphasize the bad news 3. Select ALL that applyTo build paragraph coherence,...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called without instantiating the class and returns a random Date between Jan 1, 2000 and Dec 31, 2010.
Which of the following is not a valid method for determining life insurance needs? Group of...
Which of the following is not a valid method for determining life insurance needs? Group of answer choices The Financial Needs Method. The Human Life Value Method. The Dependency Method. The Capitalization of Earnings Method.
Which ones in the following list are properties of a normal density function ? Group of...
Which ones in the following list are properties of a normal density function ? Group of answer choices
In Java: Write a method called copy, which is passed A[], which is an array of...
In Java: Write a method called copy, which is passed A[], which is an array of int, and an integer n. The method returns a new array consisting of the first n items in A[]. Write a method called slice, which is passed A[], which is an array of int, an integer i and an integer j. The method returns a new array consisting of all of the items in A from A[i] to A[j] inclusive.
1. The ease with which an investment can be converted into cash is called: a. convertibility....
1. The ease with which an investment can be converted into cash is called: a. convertibility. b. liquidity. c. profitability. d. exchangeability. e. redemption value. 2. The goals of monetary policy as controlled by the Federal Reserve are continue economic growth, full employment and: a. minimal tax rates for individuals. b. low interest rates. c. stable prices. d. no inflation. e. low consumer goods prices. 3. Rather than invest in the stock of just one or two companies, you purchase...
For each group in the following list find the order of each element in the group:...
For each group in the following list find the order of each element in the group: Z12, U(10) and U(12).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT