OUTPUT/INPUT

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What output will the following python command produce: >>> print (1,000,000)

1 0 0

What output will the following code produce? def area(l, w): temp = l * w; return temp l = 4.0 w = 3.25 x = area(l, w) if ( x ): print (x)

13.0

What output will the following python commands produce: >>> n = 17 >>> print (n)

17

Given the following code, what will the output be? import string index = "Ability is a poor man's wealth".find("w") print(index)

24

What is the output of the following statements? pi = int(3.14159) print (pi)

3

What output will the following python commands produce: x = 5 if x % 2 == 0: print (x) else: print (x, x%2)

5 1

What output will the following code produce? print ("%s %d %f" % (5, 5, 5))

5 5 5.000000

What does function subroutine do? def subroutine( n ): while n > 0: print (n,) n -= 1

Counts from n down to 1 and displays each number

What does function subroutine do? def subroutine(n): while n > 0: print (n,) n -= 1

Counts from n down to 1 and displays each number

Given the following code, what will the output be? mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"] a=0 while a < 7: print (mylist[a],) a += 2

now is the time

What is the output of the following statements? pi = float(3.14159) print (pi)

3.14159

What output will the following python commands produce: >>> print (2 * (3-1))

4

What will the output of the following program be? i=0 while (i < max(1, 22-4*5, 3*5-3*4, 2**2)): i+= 1 print (i)

4

What output will the following python commands produce: >>> print (2*3-1)

5

What does the import statement in the following script do? import StringIO output = StringIO.StringIO() output.write('First line.\n') output.close()

It includes a Python module called StringIO into the script

What will the following code segment do? infile.readlines()

Read all remaining lines in a file

What will the contents of mylist be after the following code has been executed? >>> mylist = [1, 4, 2, 3] >>> mylist.append(5)

[1, 4, 2, 3, 5]

Given the following code what will the output be? def find(strng, ch): index = 0 while index < len(strng): if strng[index] == ch: return index index += 1 return -1 print (find("the doctor is in", '*'))

-1

What output will the following python commands produce: x=1 y=2 if x == y: print (x, "and", y, "are equal") else: if x < y: print (x, "is less than", y) else: print (x, "is greater than", y)

1 is less than 2

What output will the following code produce? n = 10 while n != 1: print (n,) if n % 2 == 0: # n is even n = n // 2 else: # n is odd n = n * 3 + 1

10 5 16 8 4 2

What output will the following python command produce: >>> percentage = ( 60 * 100) // 55 >>> print (percentage)

109.0909090909091

What output will the following python command produce: >>> percentage = float ( 60 * 100) / 55 >>> print (percentage)

109.0909090909091

What output will the following python command produce: percentage = ( 60.0 * 100.0 ) / 55.0 print (percentage)

109.0909090909091

What output will the following code produce? mylist = [ [2,4,1], [1,2,3], [2,3,5] ] a=0 b=0 total = 0 while a <= 2: while b < 2: total += mylist[a][b] b += 1 a += 1 b = 0 print (total)

14

What output will the following python commands produce: n = 10000 count = 0 while n: count = count + 1 n = n // 10 print (count)

5

What output will the following statements produce using Python IDLE in interactive mode? >>> n = 2 >>> n += 5 >>> n

7

hat output will the following python commands produce: >>> print ((1+1)**(5-2))

8

What will the output of the following code be? def recursive( depth ): depth+=1 while (depth < 5): ret = recursive(depth) return depth ret = recursive( 0 ) print ("the recursive depth is ", ret)

: None

What will the output of this program be when it is executed? def test_function( length, width, height): print ("the area of the box is ", length*width*height) return length*width*height l = 12.5 w = 5 h = 2 test_function(l, w, h) print ("The area of the box is ", length*width*height)

A NameError because a variable not defined

The following code is an example of what principle? bruce = 5 print (bruce,) bruce = 7 print (bruce)

Multiple assignment

What output will the following Python script produce? def function2(param): print (param, param) def function1(part1, part2): cat = part1 + part2 function2(cat) chant1 = "See You " chant2 = "See Me " function1(chant1, chant2)

See You See Me See You See Me

What will the output of this python program be? def test_function( length, width, height): print ("the area of the box is ",length*width*height) return length*width*height l = 12.5 w = 5 h = 2 test_function(l, w, h)

The area of the box is 125.0

The following Python script will generate an error when executed. What is the cause of the error? def function2(param): print (param, param) print (cat) def function1(part1, part2): cat = part1 + part2 function2(cat) chant1 = "See You " chant2 = "See Me " function1(chant1, chant2)

The variable cat is local to function1 and cannot be used in function2

Expressions evaluate to either true or false. What will the output of the following code be when the expression "Ni!" is evaluated? if "Ni!": print ('We are the Knights who say, "Ni!"') else: print ("Stop it! No more of this!")

We are the Knights who say, "Ni!"

The output of the following code will be: fruit = "banana" letter = fruit[1] print (letter)

a


Ensembles d'études connexes

APUSH ch 14 multiple choice questions, APUSH CH 13 multiple choice questions, Apush Quizlet

View Set

HRM Chapter 13—Managing Employee Benefits

View Set

California: Real Estate Principles - Chapter 26

View Set

Test 3 - Performance Management (11)

View Set