INSY final

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

global

A ______________ variable is accessible to all the functions in a program file.

Accumulator

A variable used to keep a running total is called a(n)

Repetition

A(n) _________ structure is a structure that causes a statement or a set of statements to execute repeatedly.

flowchart

A(n) __________ is a diagram that graphically depicts the steps that take place in a program?

argument

A(n) ____________ is any piece of data that is passed into a function when the function is called.

control

A(n) _______________ structure is logical design that controls the order in which a set of statements execute.

68

After the execution of the following statement, the variable price will reference the value ___________. price = int(68.549)

float

After the execution of the following statement, the variable sold will reference the numeric literal value as (n) ___________ data type. sold = 256.752

{1, 4}

After the following code executes, what elements will be stored in set3? set1 = set([1,2,3]) set2 = set([2,3,4]) set3 = set1.symmetric_difference(set2)

{' ','1', '2', '3', '4'}

After the following statement executes, what will be stored in myset set? myset = set('1 22 333 4444')

print(format(number,',.2f'))

Assume the following statement has been executed: number = 1234567.456 write a python statement that displays the value referenced by the number variable formatted as 1,234,567.46

1. 49 2. 4 3. 3 4. 1

Assume the variables result, x, and y are all integers, and that x = 7, and y = 2. What value will be stored in result after each of the following statements execute? 1. result = x ** y 2. result = y * 2 3. result = x // y 4. result = x % y

6

Consider the following Python program that prints one line of text: val = int(input('enter a number: ')) if val < 10: if val != 5: print("wow, end=") else: val += 1 else: if val == 17: val += 10 else: print("whoa", end=") print(val) what will the program print if the user provides the following input?

hours_worked = 0.0 pay_rate = 0.0 gross_pay = 0.0 hours_worked = float(input('Enter hours worked: ')) pay_rate = float(input('Enter pay rate: ')) gross_pay = hours_worked * pay_rate print('\nGross pay is $',format(gross_pay,'.2f'))

Following program have a few syntax errors, please debug (rewrite) the program so that it will run successfully to generate an output as shown below: Enter hours worked: 34 Enter pay rate: 7 Gross pay is $238.00 hours_worked = 0.0 pay_rate = 0.0 gross pay = 0.0 hoursworked = float(input('Enter hours worked:")) pay_rate = float(input('Enter pay rate:') hours_worked * pay_rate = gross_pay print('Gross pay is $' format(gross_pay,'.2f'))

Both a & c (equal to & greater than)

If the start index is _____________ the end index, the slicing expression will return an empty string.

!=

In Python the ____________ symbol is used as the not-equal-to operator.

list

In Python, a comma-separated sequence of data items that are enclosed in a set of brackets is called

key

In a dictionary, you use a(n) ____________ to locate a specific value.

import matplotlib.pyplot

In order to create a graph in Python, you need to include

True

Indexing works with both strings and lists.

1. empty 2. 10,8,6,4,2 3. -2,-1,0,1 4. empty 5. empty 6. empty

List the sequence produced by the following range functions: Example: range(10) ans. 0,1,2,3,4,5,6,7,8,9 1. range(-10) 2. range(10,0,-2) 3. range(-2,2) 4. range(1,1) 5. range(1,-1) 6. range(0)

compound

Multiple Boolean expression can. be combined by using a logical operator to create_____________expressions.

a = 100 while a > -100: a = a - 10 print('*',end=' ') print()

Rewrite the code shown below so that it uses a while instead of a for. Your code should behave identically. for a in range(100, -100, -10): print('*',end=' ') print()

Level = int(input("Enter performance level (1-3): ")) if Level == 1: print("\nIntroductory"); elif Level == 2: print("\nIntermediate") elif(Level == 3): print("\nAdvanced") else: print("\nPlease enter performance level number between 1-3.")

Rewrite the code using if-elif-else level1 = int(input("Enter performance level (1-3) : ")) if Level == 1: print("\nIntroductory"); else: if Level = 2: print("\nIntermediate") else: if(Level == 3): print("\Advanced") else: print("\nPlease enter performance level number between 1-3.")

input()

The ________ built-in function is used to read a number that has been typed on the keyboard.

Header

The first line in a function definition is known as the function

priming read

The first operation is called the ____________ and its purpose is to get the first input value that will be tested by the validation loop.

False

The following code will display 'yes + no': mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr)

False

The following expression is valid: string = 'i' string[0] = 'i'

\

The line continuation character is a

once a tuple is created, it cannot be changed

The primary difference between a tuple and a list is that

for n in range(1, 11, 2): print(n)

Translate the while loop into for loop for the same output: n = 1 while n <- 10: print(n) n += 2

o through 11

What are the valid indexes for the string 'UT Arlington'?

x is less than or equal to y

What does the following expression mean? x <= y

it accepts 3 test scores for each of 3 students and outputs the average for each student

What does the following program do? student = 1 while student <= 3: total = 0 for score in range(1, 4): score = int(input("Enter test score:")) total += score average = total/3 print("Student", student, "average:",average) student += 1

The function get_num() is expected to return a value for num1 and for num2.

What does the following statement mean? num1, num2 = get_num()

It returns a default value.

What does the get method do if the specific key is not found in the directionary?

Processing a tuple is faster than processing a list.

What is an advantage of using a tuple rather than a list?

{1: 'January', 2: 'February', ... 12: 'December'}

What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)?

Floating point division returns a floating point number that may include fractions. Integer division returns an integer and ignores any fractional part of the division result.

What is the difference between floating-point division and integer division?

Pseudocode

What is the informal language, used by programmers use to create models of programs, that has no syntax rules and is not meant to be compiled or executed?

Dictionaries are not indexed by number.

What is the number of the first index in a dictionary?

i = 7 j = 7 k = 3

What is the output of the following Python code fragment? i = 7 j = 5 k = 3 if i < j: if j < k: i = j else: j = k else: if j > k: j - i else: i = k print("i =", i, " j =", j, " k =", k)

15 0 -3

What is the output of the following code? for n in [15, 0, -3]: print(n, ' ', end=' ')

SyntaxError: can't assign to literal

What is the output of the following code? __________________ 24 = age print("you are eligible for voting")

12

What is the output of the following command, given that value1 = 2.0 and value2 = 12?

The path is D:\sample\test.

What is the output of the following print statement? print('The path is D:\\sample\\test.')

0 1 2 3 4

What is the output of this code? 1st = [2, 3, 4, 5, 6] for index in range(len(1st)): 1st[index] = index print(1st[index], end=' ')

[50, 3, 11, 37, 9, 9, 31]

What is the output of this code? 1st = [50, 70, 11, 13, 1, 9, 29, 31] 1st[1] = 3 del 1st[3] 1st[3] = 37 1st[5] = 1st[4] print(1st)

1 2

What is the output? def foo(): try: print(1,end=' ') finally: print(2,end=' ') foo()

6

What is the output? outfile = open('myfile.txt','w') print(outfile.write('PYTHON'))

1 3 6 10

What is the output? sum = 0 #Initialize sum for i in range(1,5): sum += i print(sum)

1 2 3 4

What is the output? _____________ def loopTest(): n=0 while n < 10: n += 1 if n == 5: break print(n,end=' ') loopTest()

Error

What is the output?________________________ x = 0 def variable_Scope(): x += 100 return x print(variable_Scope())

pickling

What is the process used to convert an object to a stream of bytes that can be saved in a file?

False

What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? not(x < y or z > x) and y < z

False

What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y and z > x

the string with all leading whitespaces removed

What is the return value of the string method Istrip()?

{'John': '5556666', 'Julie': '5557777'}

What is the value of the variable phones after the following code executes? phones = {'John': '5555555', 'Julie': '5557777'} phones['John'] = 5556666

a quote mark (")

What symbol is used to mark the beginning and end of a string?

count-controlled loop

What type of loop structure repeats the code a specific number of times?

'Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:]

nothing will display

What will be displayed after the following code executes? guess = 19 if guess < 19: print("Too low") elif guess > 19: print("Too high")

yesyesyesno

What will be displayed after the following code executes? mystr = 'yes' yourstr = 'no' mystr += mystr*2+yourstr print(mystr)

{'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

What will be displayed after the following code executes? cities = {'GA': 'Atlanta', 'NY': 'Albany', 'CA': 'San Diego'} if 'CA' in cities: del cities['CA'] cities['CA'] = 'Sacramento' print(cities)

30

What will be displayed after the following code is executed? for num in range(0, 20, 5): num += num print(num)

Nothing; there is no print statement to display average. The ValueError will not catch the error.

What will be the output after the following code is executed and the user enters 75 and -5 at the first two prompts? def main(): try: total = int(input("Enter total cost of items?")) num_items = int(input("Number of items")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') main()

Nothing; the number of x-coordinates do not match the number of y-coordinates.

What will be the output after the following code is executed? import matplotlib.pyplot as plt def main(): x_crd = [0, 1, 2, 3, 4, 5] y_crd = [2, 4, 5, 2] plt.plot(x_crd, y_crd) main()

64

What will be the output after the following code is executed? def pass_it(x,y): z = y**x return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer)

KeyError

What will be the result of the following code? ages = {'Aaron': 6, 'Kelly': 3, 'Abigail': 1} value = ages['Brianna']

[1, 2, 1, 2, 1, 2]

What will be the value of the variable list after the following code executes? list = [1, 2] list = list * 3

[1, 2, 3]

What will be the value of the variable list2 after the following code executes? list1 = [1, 2, 3] list2 = [] for element in list1: list2.append(element) list1 = [4, 5, 6]

Invalid, must contain one number.

What will display after the following code executes? password = 'ILOVEPYTHON' if password.isalpha(): print('Invalid, must contain one number.') elif password.isdigit(): print('Invalid, must have one non-numeric character.') elif password.isupper(): print('Invalid, cannot be all uppercase characters.') else: print('Your password is secure!')

IS@ISOM@Business@UTA

What will the following statement display? print('IS', 'ISOM', 'Business', 'UTA', sep='@')

executed

When a function is called by its name during the execution of a program, then it is

and

When using the __________ logical operator, both subexpressions must be true for the compound expression to be true.

or, and

Which logical operators perform short-circuit evaluation?

**

Which mathematical operator is used to raise 5 to the second power in python?

tuple

Which method can be used to convert a list to a tuple?

readline

Which method will return an empty string when it has attempted to read beyond the end of a file?

find(substring)

Which method would you use to determine whether a certain substring is present in a string?

items

Which method would you use to get all the elements in a dictionary returned as a list of tuples?

pop

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

The elements are in pairs.

Which of the following does not apply to sets?

the file object

Which of the following is associated with a specific file and provides a way for the program to work with that file?

if y >= 10 and y <= 50;

Which of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive?

infile = open('users.txt','r')

Which of the following is the correct way to open a file named users.txt in 'r' mode?

total += number

Which of the following represents an example to calculate the sum of numbers (that is, an accumulator), given that the number is stored in the variable number and the total is stored in the variable total?

a del statement

Which of the following would you use if an element is to be removed from a specific index?

open the file

Which step creates a connection between a file and a program?

random

Which type of file access jumps directly to a piece of data in the file without having to read all the data that comes before it?

del

Which would you use to delete an existing key-value pair from a dictionary?

val = int(input('enter a number:')) if val >= 1 and val <= 100: print('OK')

Write a Python program that requests an integer value from the user. If the value is between 1 and 100 inclusive, print "OK;" otherwise, do not print anything.

num = int(input('enter a number: ')) while num < 0: print('invalid data') num = int(input('enter a positive nonzero number : '))

Write code that prompts the user to enter a positive nonzero number and validates the input:

input validation

________ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in a computation .

0

def Circumference(): r=0 PI = 3.14159 #Formula for the area of a circle given its radius C = 2*PI*r #Get the radius from the user r = float(input("Please enter the circle's radius: ")) #Print the circumference print("Circumference is", C) Circumference() What is the output of this program if the user input for the radius is 5? ________________

19

def sum(m=0, n=1, r=10): return m + n + r print(sum(4,5)) what is the output? ____________________________

0

def sum(m=0, n=1, r=10): return m + n + r print(sum(r=0, n=0))

condition-controlled loop

what type of loop structure repeats the code based on the value of Boolean expression?

a try/except statement

which statement can be used to handle some of the runtime errors in a program?


Ensembles d'études connexes

English 11 Unit 1 synonyms and antonyms

View Set

microbiology theory final exam chapters 1-15

View Set

Unix II: Chapter 6 "Software Installation and Management" "STUDY GUIDE"

View Set