click below
click below
Normal Size Small Size show me how
Comp. Sci. - Python
Quizzes 6 - 9
Question | Answer |
---|---|
State the 4 points of the while-loop checklist | 1. Choose a variable to control the loop 2. Initialize that variable BEFORE the loop 3. Use that variable in the (Boolean) statement of the while-loop 4. Alter the value of the variable in the loop so that eventually the expression becomes fale |
Define data coverage testing | testing the program; test cases are chosen with all the data relevant to the program |
Write a program fragment that uses a while-loop to compute the sum of the even integers from 200 through 400. Print the sum after it is completed. | number = 200 total = 0 while number <= 400: total += number number += 2 print(total) |
Show the exact output that this program would print on the screen if run. size = 32 while size > 3: print(size) size = size // 2 print(size) | 32 16 8 4 2 |
Define data structure | An aggregate of data that can be handled as a unit |
How many bits does ASCII (or EBCDIC) use to represent each character? | 8 |
How many bits does Unicode use to represent each character? (just fyi, not on a quiz or test that I know of...) | 16 (also, ASCII, Unicode, and EBCDIC are called 'character sets') |
Which of these character sets has the most characters: ASCII, EBCDIC, or Unicode? | Unicode |
Which of these character sets includes the Greek alphabet: ASCII, EBCDIC, or Unicode? | Unicode |
Given the variables below, show the value of the variable 'result' after each of these statements. fruit = strawberry index = 6 a. result = (fruit == "fruit") b. result = len(fruit) c. result = fruit[index - 1] d. result = fruit[-1] | a. False b. 10 c. fruit[5] = 'b' d. 'y' |
List the 3 points of the function checklist | 1. What does it do (OR compute)? 2. What goes in? 3. What comes out? |
Suppose a function called 'flag' requires three parameters called 'red', 'white', and 'blue'. Write the 'def' statement that appears at the beginning of this function. | def flag(red, white, blue) |
A developer writes a small main program to call the 'quizFunc' function repeatedly with carefully chosen test data as its arguments. Later, that function will be used with other functions in a completed application. What kind of testing is this? | unit testing (that small main program used to call the function is called a 'driver') |
After coding and testing several functions separately, the developer combines the functions and tests them together along with a main program. What kind of testing is this? | integration testing |
Write a complete function definition (including the 'def' statement and the body of the function) for a function that computes the area of a rectangle, given its length and width | def area of rectangle (length, width): area = length * width return area |
Write a statement to open a file for reading. The file variable is 'quizFile'. The physical file name is 'bisondata.txt'. | quizFile = open("bisondata.txt", "r") |
Let'outfilevar' be a file variable that is open for writing. Write a program fragment that writes 'Lipscomb' and then writes 'University' on the next line. | outfilecar.write("Lipscomb\nUniversity") |
Write the statement that enables your program to use any use any of the functions in the Math module. | import math |
Suppose you have a text file called 'lipscomb.txt' on your computer. Write a small program that opens 'lipscomb.txt', reads the entire file, and prints it on the screen. | outputfile = open("lipscomb.txt", "r") for line in outputfile: print( line.strip() ) outputfile.close() OR (the following also works) outputfile = open("lipscomb.txt", "r") text = outputfile.read() print(text) outputfile.close |