Python Exam
what will the following program display? for r in range (1, 4): for c in range (r): print ('#', end = ' ') print( )
# ## ###
what will the following code display? for x in range (10, 15, 2): print(x)
10 12 14
ASCII is an encoding scheme that uses a set of __________ to store characters in a computer's memory.
128 numeric codes
Assume the variable upper_limit is assigned the value 50. How many times will the following for loop iterate? for x in range(0, upper_limit):
50
a byte is made up of _____ bits
8
what part of the computer actually runs programs
CPU
the following logical expression evaluates to either true or false. choose the correct result False and False
False
the following logical expression evaluates to either true or false. choose the correct result False and True
False
the following logical expression evaluates to either true or false. choose the correct result False or False
False
the following logical expression evaluates to either true or false. choose the correct result True and False
False
the following logical expression evaluates to either true or false. choose the correct result not True
False
the following logical expression evaluates to either true or false. choose the correct result False or True
True
the following logical expression evaluates to either true or false. choose the correct result True and True
True
the following logical expression evaluates to either true or false. choose the correct result True or False
True
the following logical expression evaluates to either true or false. choose the correct result True or True
True
the following logical expression evaluates to either true or false. choose the correct result not False
True
a bit is
a binary digit, like 0 or 1
Assume the variable age has been assigned an integer value, and the variable is_full_time_student has been assigned a Boolean value (True or False). Write an expression that evaluates to True if age is less than 19 or is_full_time_student is True.
age < 19 or is_full_time_student == True
In mathematics, the notation n! represents the factorial of the nonnegative integer n. The factorial of n is the product of all the nonnegative integers from 1 to n. For example: 7! = 1 x 2 x 3 x 4 x 5 x 6 x 7 = 5,040 Write a program that lets the user enter a nonnegative integer and then uses a loop to calculate the factorial of that number. Print the factorial to standard output.
ans=1 n=int(input("Enter a nonnegative integer:")) while (n>0): ans *= n n=n-1 print(ans)
word processing programs, spreadsheet programs, email programs, web browsers, and game programs belong to what category of software
application software
Write code that assigns the average of the numbers from 1 to n (where n is a positive integer value) to the variable avg.
avg = (1 +n)/ 2
Calculate the average of the variables a, b, and c, and assign the result to a variable named avg. Assume that the variables a, b, and c have already been assigned a value, but do not assume that the values are all floating-point. Make sure the value that you assign to avg is a floating-point value.
avg = (a + b + c) / 3
a while loop tests its expression
before each iteration
a tiny "switch" that can be set to on or off is called a
bit
Given a variable bridge_players, write a statement that increases its value by 4.
bridge_players += 4
what type of program translates a high-level language program into a separate machine language program
compiler
a logical design that controls the order in which a set of statements execute is known as a
control structure
A cookie recipe calls for the following ingredients: • 1.5 cups of sugar • 1 cup of butter • 2.75 cups of flour The recipe produces 48 cookies with this amount of ingredients. Write a program that asks the user how many cookies they want to make and then displays the number of cups of each ingredient needed for the specified number of cookies. When the program asks the user for the number of cookies, it should display the following string as a prompt: 'Enter number of cookies:' When the program displays the number of cups of ingredients, it should display a message in the following format: You need x cups of sugar, y cups of butter, and z cups of flour. Where x is the number of cups of sugar, y is the number of cups of butter, and z is the number of cups of flour. Don't worry about formatting the numbers in the output.
cookies = input('Enter number of cookies: ') c = (int(cookies)) x = c/48*1.5 y = c/48*1.0 z = c/48*2.75 print("You need " + str(x) + " cups of sugar, " + str(y) + "cups of butter, and " + str(z) + " cups of flour." )
a program structure that can execute a set of statements only under certain circumstances is called a
decision structure
The results of a(n) ________ are sent out of a program as output.
executing process
any data that is stored in binary is known as analog data: t or f
false
the amount of memory enough to store a letter of the alphabet or a small number is one bit: t or f
false
after the statements below execute, what is the Python data type of the values referenced by each variable? value1 = 45.9 value2 = 7.0
float
what term refers to the physical devices or components of which a computer is made
hardware
In this exercise, use the following variables: I, lo, hi, and result. Assume that lo and hi each are assigned an integer and that result is assigned 0. Write a while loop that adds the integers from lo up through hi (inclusive), and assigns the sum to result. Your code should not change the values associated with lo and hi. Also, just use these variables: I, lo, hi, and result.
i = lo result = 0 while i <= hi: result = result + i i += 1
Write an if-else statement that compares the age variable with the value 65. If age is greater than or equal to 65, add 1 to senior_citizens. Otherwise, add 1 to non_seniors.
if age >= 65: senior_citizens = senior_citizens +1 else: non_seniors = non_seniors + 1
Assume that ph has been assigned a float. Write an if-else-if statement that compares ph to 7.0 and makes the following assignments (respectively) to the variables neutral, base, and acid: - 0,0,1 if ph is less than 7 - 0,1,0 if ph is greater than 7 - 1,0,0 if ph is equal to 7
if ph < 7: neutral = 0 base = 0 acid = 1 elif ph > 7: neutral = 0 base = 1 acid = 0 else: neutral = 1 base = 0 acid = 0
Assume the variables x and y have each been assigned an int. Write a fragment of code that assigns the greater of these two variables to another variable named max.
if x > y: max = x else: max = y
write an expression that evaluates to True if the value of index is greater than the value of last_index
index > last_index
after the statements below execute, what is the Python data type of the values referenced by each variable? value1 = 99 value2 = 7
int
an execution of the statements in the body of a loop is called a(n)
iteration
what part of the computer serves as a work area to store program and its data while the program is running
main memory
The date June 10, 1960, is special because when it is written numerically, the month time the day equals the year: 6/10/60 --> 6*10 = 60 Write a program that asks the user to enter a month (in numeric form), a day, and a two-digit year in three separate input statements. The program should determine whether the month times the day equals the year. If so, it should print, "This date is magic!" Otherwise, it should print, "This date is not magic."
month = int(input('Enter month (numeric):')) day = int(input('Enter day:')) year = int(input('Enter two digit year:')) day_month = day * month if day_month == year: print('This date is magic!') else: print('This date is not magic.')
what fundamental set of programs control the internal operations of the computers hardware
operating system
Monitors, printers, and status lights are all examples of ________ devices
output
in a flowchart, _____ are terminal symbols
ovals
in a flowchart, _____ are either input or output
parallelograms
Write a math expression that computes the remainder of the variable principal when divided by the variable divisor. (Assume that each is refers to an int.)
principal % divisor
create a code to print the number 65.4321 with only 2 decimal places
print (format( 65.4321, '.2f'))
Given two variables iVal and fVal, containing respectively an integer and a float value, write a statement that writes both of their values to standard output in the following format: i=iVal f=fVal.
print("i=" + str(iVal), "f=" + str(fVal))
When a program runs on a computer, it is stored in
ram
in a flowchart, _____ are processing symbols
rectangles
a condition-controlled loop in Python
relies on a true-false state
write a boolean expression that is True if the variable s does not reference the string "end".
s != "end"
write a boolean expression that is true if s references the string "end".
s == "end"
what part of the computer holds data for long periods of time, even when there is no power to the computer
secondary storage
a program is a(n) _____ that a computer follows to perform a task
set of instructions
a single function that the program must perform in order to satisfy a customer is known as
software requirement
the code that a programmer writes is called
source code
after the statements below execute, what is the Python data type of the values referenced by each variable? value1 = ' abc '
str
Each language has a set of rules that must be strictly followed when writing a program. What is this set of rules called?
syntax
A mistake that is usually caused by a misspelled key word, a missing punctuation character, or the incorrect use of an operator is called a
syntax error
Given that n refers to a positive integer, use a while loop to compute the sum of the cubes of the first n counting numbers, and assign this value to total.
total = 0 k = 1 while k <= n: total += k**3 k += 1
in a single alternative decision structure, if the condition that is being tested is _____, the program takes the alternative path
true
the binary numbering system are all numeric values written as sequences of 0s and 1s: t or f
true
what coding scheme is extensive enough to represent the characters of many of the languages in the world
unicode
what do you call a program that performs a specialized task such as virus scanner, a file compression program, or a data backup program
utility program
Assume x refers to an int. Write a Boolean expression that is True if the variable x refers to an even number.
x % 2 == 0
write a boolean expression that is True is the value of x is equal to 0
x == 0
Assume the variables x and y have been assigned integer values. Write an expression that evaluates to True if x is non-negative and y is negative.
x >= 0 and y < 0