256 Exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Write an expression that accesses the first character of the string my_country.

my_country[0]

Is the following a valid function definition beginning? Type yes or no. def my_fct(userNum + 5):

no

Assign num_neg to the number of below freezing Celsius temperatures in the list. temperatures = [30,20,2,-5,-15,-8,-1,0,5,35] num_neg = 0 for temp in temperatures: if temp < 0: ____________________________

num_neg += 1

Iterate the string '911' using a variable called number: for________________________:

number in '911'

Print the length of the string variable first_name.

print(len(first_name))

def print_sum(num1, num2): print(num1, '+', num2, 'is', (num1 + num2)) Write a function call using print_sum() to print the sum of x and 400 (providing the arguments in that order).

print_sum(x, 400)

when the code says: import random, the line is importing the ____________________________________________

random module

Write range function for every integer from 0 to 500.

range(0, 501)

Write range function for every integer from 10 to 20.

range(10, 21)

Write range function for every 2nd integer from 10 to 20.

range(10,21,2)

Write range function for every integer from 5 to -5.

range(5,-6,-1)

Print scores in order from highest to lowest. Note: List is pre-sorted from lowest to highest scores: [75,77,80,85,90,95,99] for scr in __________________________: print(scr, end=" ")

reversed(scores)

Write a statement that splits a $25 check among 3 people and leaves a 25% tip. Use the default tax rate.

split_check(amount=25.0, num_people=3, tip_percentage=0.25)

Write a statement that splits a $50 check among 4 people. Use the default tax percentage and tip amount.

split_check(amount=50, num_people=4)

x = 0 y = 5 z = ? while x < y: if x == z: print('x == z') break x += 1 else: print('x == y') What is the output of the code if z is 10? x == z x == y

x == y

x = 0 y = 5 z = ? while x < y: if x == z: print('x == z') break x += 1 else: print('x == y') What is the output of the code if z is 3? x == z x == y

x == z

Functions are like their own little programs. They make input, which we call the function arguments (or parameters) and give us back output that we refer to as return values.

Arguments

A function may return multiple objects. True False

False

A key reason for creating functions is to help the program run faster.

False

Given: for i in range(5): if i < 10: continue print(i) The loop will only iterate once. True False

False

Given: for i in range(5): if i < 10: continue print(i) The loop will print at least some output. True False

False

Maps the visible names in a scope to objects. Namespace Scope locals() Scope resolutions

Namespace

The area of code where a name is visible. Namespace Scope locals() Scope resolutions

Scope

The process of searching namespaces for a name. Namespace Scope locals() Scope resolutions

Scope resolution

y = 1 + print_val(9.0) valid? True False

false

y = square_root() valid? True False

false

Variable created outside of functions and user- define functions are in the ___________ scope.

global

Loop iterates 10 times. i = 1 while_____________: i = i +1

i <= 10

Loop iterates over the odd integers from 1 to 9 (inclusive). i = 1 while <= 9: _______________

i = i + 2

Returns a dictionary of the names found in the local namespace. Namespace Scope locals() Scope resolutions

locals( )

Whats z if a = 4, b = 5, c = 20? mult = 0 while a < 10: mult = b * a if mult > c: break a = a + 1 z = a

5

Given the following code, how many times will the inner loop body execute? for i in range(2): for j in range(3): # Inner loop body

6

Whats z if a = 1, b = 1, c = 0? mult = 0 while a < 10: mult = b * a if mult > c: break a = a + 1 z = a

1

print_pizza_area() print_pizza_area() how many function definitions of print_pizza_area() exist?

1

print_pizza_area() print_pizza_area() how many print statements would exist?

1

print_pizza_area() print_pizza_area() how many function calls of print_pizza_area() exist?

2

print_pizza_area() print_pizza_area() how many outputs would execute?

2


Conjuntos de estudio relacionados

Physiology - Questions - Block 3 - BRS - Renal

View Set

Penny Abdomen Review, Davies Abdomen

View Set

Comparative Politics Ch. 1: The Comparative Approach: An Introduction

View Set

Chapter 1: An Introduction to the Human Body

View Set

Intro to the New Testament Final Exam

View Set

Introduction to Machine Learning

View Set