Python Final Study Guide

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

I want to convert a number to a percentage. It is safe to assume the number is purely a decimal format (for example: 0.23 is 23 percent). Which code will correctly format the decimal into a "pretty" percent for me. For example: 0.23 should print 23%. Assume *no* partial percents (no decimal places after conversion). There may be more than one correct answer. 1) value = 1/3 print(f"{int(value*100):d}%") 2) value = int(1/3 * 100) print(f"{value:.0f}%") 3) value = int(1/3 * 100) print(f"{value:0f}%") 4) value = int(1/3 * 100) print(f"{value:d}%")

1) value = 1/3print(f"{int(value*100):d}%") 4) value = int(1/3 * 100) print(f"{value:d}%")

Given the following code: def kitty_check(kitties): if kitties < 5: return "Not enough purrs" if kitties <= 13: return "Purrrfect" return "Are there really too many purrs?" Mark all the values that would return "Are there really too many purrs?" 0 12 100 5 13

100

I want following method to return a factorial - so for example, factorial(5) would return 120 (5*4*3*2*1) def factorial(n): result = 1 while n [C] 1: result *= n n -= 1 return result what type of conditional would I replace [C] with for the code to work properly? 1) <= 2) > 3) < 4) != 5) ==

2) >

Given the following code: def puppy_check(puppies): if puppies < 10: response = "Not enough puppies" elif puppies < 100: response = "Yay puppies!" else: response = "Ok, that is a lot of puppies." return response print(puppy_check(0)) What is printed? 1) Yay puppies! 2) Not enough puppies 3) Ok, that is a lot of puppies.

2) Not enough puppies

Given the following code, how many times is "Order 66" printed? def order66(execute): counter = 0 while counter < execute <= 66: print("Order 66") counter += 1 order66(5)

5

T/F: Strings are mutable objects, meaning that writing or altering individual characters of a string variable is allowed.

False

The following instructions are equivalent: print("Hello World!") print('Hello World!')

True

Given the following blocks of code, categorize them as valid (they will compile) or invalid (they will not compile) Valid? Invalid? name = "Spot!" PI = 3.14 puppyCounter = int(input("Enter the number of Puppies")) dbl = " " 3val = 3 puppyCounter = int(input(Enter the number of Puppies)) break = 10 $counter$ = 0

Valid: name = "Spot!" PI = 3.14 puppyCounter = int(input("Enter the number of Puppies")) dbl = " " Invalid: 3val = 3 puppyCounter = int(input(Enter the number of Puppies)) break = 10 $counter$ = 0

Given the following function def longerFunc(input1, input2, input3): print("Hello " + input1) print("Cryptography is the " + input2) input3 = input3 + input3 / 2 print("The hidden number is:") print(int(input3)) and the following output Hello Valentine Cryptography is the bombe The hidden number is: 15 Complete the method call below with the correct parameter values. Remember to be exact. "Ada" and Ada are two different symbols in programming. one is a String, the other is a variable. For any numbers, you should use whole numbers only. Answers should not include a space, or they will get marked wrong! longerFunc(__,__,__)

longerFunc("Valentine", "bombe", "15")

Which pair of statements print output on the same line? 1) print("Hello ", end='') print("World!") 2) print("Hello ") print("World") 3) print(Hello , end = ' ') print(World!, end = ' ')

print("Hello ", end='') print("World!")

Given the following functions, align the function call (input) with the returned value def weirdDiv(first, second): print(first) first = first * 2 return first / second def weirdDivIntOnly(first, second): print(second) first = first * 2 return int(first / second) def weirdMul(first, second, third): print(third) return third * second / first weirdDiv(5, 20) - ? weirdMul(2.0, 5, 10) - ? weirdDivIntOnly(5, 40.0) - ?

weirdDiv(5, 20) - 0.5 weirdMul(2.0, 5, 10) - 25.0 weirdDivIntOnly(5, 40.0) - 0

Given the following functions, align the function call (input) with the returned value def weirdDiv(first, second): print(first) first = first * 2 return first / second def weirdDivIntOnly(first, second): print(second) first = first * 2 return int(first / second) def weirdMul(first, second, third): print(third) return third * second / first weirdMul(2.0, 5, 10) - ? weirdDivIntOnly(1.5, 2) - ? weirdDiv(1.5, 2) - ?

weirdMul(2.0, 5, 10) - 25.0 weirdDivIntOnly(1.5, 2) - 1.0 weirdDiv(1.5, 2) - 1.5

Order the instructions below to have a code that reads three int values, calculates the average of those numbers, and prints the average. y = int(input("Enter the second number:")) average = (x + y + z)/3 print("Average of", x, ", ", y, ", and ", z, " = ", average) x = int(input("Enter the first number:")) z = int(input("Enter the third number:"))

x = int(input("Enter the first number:")) y = int(input("Enter the second number:")) z = int(input("Enter the third number:")) average = (x + y + z)/3 print("Average of", x, ", ", y, ", and ", z, " = ", average)


Ensembles d'études connexes

ZOO3731 CH 18 GENERAL & SPECIAL SENSES QUIZ QUESTIONS

View Set

Lifepac High School Health Book 1

View Set

Chapter Twelve: Monopolistic Competition and Oligopoly

View Set