Programming

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

how many numbers does this code print? i = 3 while i>=0: print(i) i = i - 1

4 because 3 is greater than 0 so you would print 3, then the code states that i = i - 1 so you would do i = 3-1 which equals 2. And 2 is greater than 0 so you would print 2. You carry on the code until you reach 0 which 0 equals 0. So 4 numbers in total would be printed.

def print_double(x): print(2 * x) print_double(3)

6 because print(2 times x) multiplies the variable (3) by two. So 3 times 2 = 6

Write a Python code segment to print the list below in reverse order. You must use a loop in your solution. list = [4,3,8,2,7,9]

list = [4,3,8,2,7,9] ind = len(list)-1 while ind > = 0: print(list[ind]) ind = ind - 1 BECAUSE ind = len(list)-1 gives the index of the last item which would be 9. So then since ind, 9, is greater than 0, it would print the last list item. Then ind = ind-1 would mean that it continues the code and subtracts it by one then runs through the code again. (shits confusing as hell)

x = 3 num = 17 print(num % x) a. 2 b. 51 c. 5.2

a. because 3 goes into 17 5 times with a remainder of ___. % is the sign for the remainder operation.

print(1+2+3+4.0+5) a. 15.0 b. 15

a. because 4.0 makes it a float

print(7 != 8) a. True b. False

a. because 7 does not equal 8

print('I couldn\'t care less about this class!') a. I couldn't care less about this class! b. I couldn\'t care less about this class! c. I couldnt care less about this class! d. 'I couldn\'t care less about this class!'

a. because it uses the apostrophe operation

Which results in two lines? a. "My bunny \n is the best" b. "Im gonna \n fail \n this" c. 'Lucy\' is \' obese' d. "I hate my life"

a. because it uses the separate line operation (and its a true statement)

nums = [9, 8, 7, 6, 5] nums.append(4) nums.insert(2, 11) print(len(nums)) a. 7 b. 9 c. 6 d. 5

a. because nums.append adds 4 to the end of the list and nums.insert inserts 11 2 spaces over

nums = [1, 2, 3, 4, 5] nums[3] = nums[1] print(nums[3]) a. 2 b. 4 c. 3 d. 5

a. because the code set num3 to num1 so it would set 4 to ___

words = ["hello"] words.append("world") print(words[1]) a. world b. hello world c. hello

a. because words.append changes hello to world then print(words[1]) would print _____

Which of the following operators is used to calculate the remainder of division a. % b. / c. ** d. //

a. is the operation for the remainder

x = 5 y = x + 3 y = int(str(y) + "2") print(y) a. 10 b. 82 c. 88

b. because 5+3 equals 8, then in the operation it converts 8 to a string and adds 8 by 2 which equals ___

spam = "7" spam = spam + "0" eggs = int(spam) + 3 print(float(eggs)) a. 70.0 b. 73.0 c. 70.0 d. 703

b. because 7 and 3 are originally strings so spam = spam + "0" will equal 70. Then 70 will be converted to an int so when it is added by 3 it will equal 73. Then in the print statement it is converted to a float so the answer will be ___

print( 8 ** (1/3) ) a. 2 b. 2.0 c. 2.3 d. 3.0

b. because if you raise a power to a fraction it becomes a square root, so the cubed root of 8 equals ___. The single / makes the answer a float.

nums = [10, 9, 8, 7, 6, 5] nums[0] = nums[1] - 5 if 4 in nums: print(nums[3]) else: print(nums[4]) a. 6 b. 7 c. 4 d. 2

b. because nums[0] = nums[1] - 5 sets the vaue of 10 to be 9 minus 5 which equals 4. So you would print ____ (Sorry this explanation was weird lol)

print( 10//4 ) a. 2.5 b. 2 c. 40

b. because the // gets rid of the remainder of 2.5

print(1 + 2 + 3) result: a. 123 b. 6

b. because the numbers are ints

How many argument(parameters) are in this function call? range(0, 100, 5) a. 105 b. 3 c. 01005

b. because there are three numbers separated by commas

print( 7 > 7.0 ) a. True b. False

b. because though one is int and one is float, they are still equal

What is the operation for an apostrophe? a. // b. \' c. \n d. %

b. is the operation for an apostrophe

What is the operation that raises a number to the power? a. * b. ** c. // d. %

b. is the operation that raises a number to the power

print(3 * '7') a. 21 a. 10 c. 777

c. because '7' is a string (not an integer) so it will type in order. 3 is how many times it will repeat

print((3**2)//2) a. 8 b. 3 c. 4 d. 4.5

c. because 3 to the power of 2 divided by 2 = 4.5 but the double division sign (//) produces an int so it would be ___

print(1 + 4*3) a. 8 b. 12 c. 13 d. 15

c. because 4*3=12+1 = ____

spam = 7 if spam > 5: print("five") if spam > 8: print("eight") a. eight b. nothing c. five d. spam

c. because 7 is greater than 5 so the print will be ___

letters = ["a", "b", "c"] letters.append("d") print(len(letters)) a. abcd b. 3 c. 4

c. because len(letters) counts the amount of numbers in a list

spam = "eggs" print(spam * 3) a. 3eggs b. "spamspamspam" c. eggseggseggs d. spamspamspam

c. because spam is a function call not a variable so spam*3 means you write the variable three times

Which of these will not be stored as a float? a. 2/4 b. 7.0 c. 7

c. because the remainder is not given

print((4+8) / 2)) result: a. 6 b. 8 c. 6.0 d. 12

c. because when you use a single / operation it produces a float

x = 4 x *= 3 # x = x*3 print(x) a. 7 b. 444 c. 12 d. 3333

c. because x = x times 3 so 3 times 4= ___

What operation do you use to separate text into two lines? a. ** b. // c. \n d. \'

c. is the operation to separate lines

x = "2" y = "4" z = int(x) + int(y) print(z) a. 8 b. 24 c. 8.0 d. 6

d. because the int converts the variables from a string to an integer so it will not print 24 but will add the numbers

What is the operation for "does not equal" a. // b. ** c. % d. !

d. is the operation for "does not equal"

Write a python function called areaRectangle() to take in width and height of a rectangle as parameters. The function will return the area of the rectangle.

def areaRectangle(width, height) return(width*height) print(areaRectangle(45,100)

What is the operation for division (finding the quotient)?

//

Write the Python code to output the quotient of dividing 100 by 42

100//42

Write a for loop to print out the numbers 5 to 50 counting by 5

for x in range (5, 51, 5): print(x) - the first digit says start at 5 - second says end at 50(1) - third says count by five OR y=5 while y <=50: print(y) y=y+5

Write Python code to output 5 raised to the 3rd power.

print(5**3)


संबंधित स्टडी सेट्स

Sales Associate Test Review Q & A

View Set

N487 Leadership in Nursing: NCLEX Review for Quiz Ch 8-12

View Set

Ch. 12 Delivering Business Presentations and Speeches

View Set

Chap 15 (psych quiz bank ch 15 Cocklin)

View Set

Social Studies: American Revolution pg. 228-231 (#19-24)

View Set

Business Data Networks & Security - Ch. 6, Business Data Networks and Security - Chapters 8, 9, 10, and 11., Business Data Networks & Security (Panko)- Ch 9- Internetworking, Business Data Networks and Security Ch 10, Business Data Networks & Securit...

View Set