Spring 2016, Monday, 4/11/16 - Juniata College



Computer Science ISpring 2016, Monday, 4/11/16100 pointsName _____________________________True/false on objects and classes.[12 pts]_____ Python objects model real life objects or abstractions._____ A class defines the variables that hold the characteristics of the object instantiations._____ A class defines the functions that access and modifies an object’s contents._____ All object instances share only one set of instance variables with all the other instances._____ Python instance variables must use the pattern like self._instVar to be referenced._____ The instance variables can only be of the types numbers, booleans and Strings._____ A constructor for a class should ensure all instance variables start with reasonable values._____ A setter method is used to change one or more instance variables._____ A getter method is used to retrieve the value of an instance variable._____ The methods of a class can share access to the instance variables._____ A reference variable to an object literally contains the entire object in its memory location._____ Two reference variables can point to the same object instantiation.[File processing]. Fill in the blanks on these file access concepts. Choose answers from the box of terms on the right. Some terms may be used more than once and some not at all.[12 pts]544830022860input outputstreams oceansbinary textif-then-else loopCSV XML open close created deletedformatted scannerUTF-8 UTF-16ASCII Unicodepersistent characters input outputstreams oceansbinary textif-then-else loopCSV XML open close created deletedformatted scannerUTF-8 UTF-16ASCII Unicodepersistent characters Input and _______ files are treated as ______________ or simple sequences of _____________. The coding of these files can be _________ or ____________. To prepare a file for processing for either reading or writing by Python we have to _________ the file, and when the processing of the data in the file is complete we should execute a __________ function. A _______ control structure is typically necessary to process a file’s contents. A Word or Excel file and some proprietary data files are known as _________ files because they cannot easily be viewed by a simple editor. The data files that can be created by an editor (Notepad or TextEdit) are known as ________ files. A special type of readable data file that has its data values separated by commas is known as a __________ file. Files are useful in a computer because the contents are ______________ after the power is turned off. Explain what the following statement does.[6 pts]inputFile = open('data.txt', 'r', encoding = 'utf-8')Fill in the blanks for a function that simulates the rolling of a single “loaded die” that rolls more 1’s and 6’s each at a probability of 25% and the remaining sides each at 12.5%.[10 pts]def roll(): _____ = random.random() if rnd ____ 0.25: return _____ elif _____ < _______: return 6 elif rnd < 0.625: return ___ elif rnd < ______ : return ____ elif rnd < 0.875: return ____ ______ return 5Answer the following questions about the following playing card function and function call.[10 pts]def newDeck(): DECK = [] for r in ['c','d','h','s']: for s in ['2','3','4','5','6','7','8','9','T','J','Q','K','A']: DECK.append(s+r) return DECKmydeck = newDeck()What kind of data structure is DECK? _______________What are the first three strings in mydeck? ___ , ____, _____What would random.choice(mydeck) return? _______________What is len(mydeck), even after an execution of c)? ________If mydeck.remove(‘Ad’) is executed, what is len(mydeck)? _________Answer the following questions about the high-low guessing game as presented in the text.[5 pts]The number to be guessed is generated with random.findrange(1,101). What is the smallest number possible? _____ and the largest number? ______If the game is played correctly, how many total guesses are necessary to zero in on the number? _____True/false. _____ This game’s zeroing in technique is useful in searching a list for a value, but the list must be sorted. True/false. _____ This high-low guessing game function is an example of a non-deterministic algorithm.True/false on text processing.[5 pts]______ We consider three characters, the space, the newline and the tab as separator characters of words.______ Combinations of spaces, newlines and tabs are called “empty space”.______ The last character of a line is denoted by ‘\n’.______ Reading a line from a file will normally include the newline. ______ If we want to get rid of leading and trailing spaces of the string variable line we can use the function of the form line.strip().String encoding. Put in order the following characters from smallest binary coding (1) to the largest (6).[5 pts]______ ______ ______ ______ ______ ______‘3’ ‘a’ ‘Q’ ‘8’ ‘ ‘ ‘y’Fill in the following program function that would scan a FASTA file for just the header information and print it. Finally print the number of header lines found.[12 pts]def headers(): ffile = _______ (‘fasta.dat’, ______, encoding=’utf-8’) count = ____ for ______ in _________: cleanline = line.________ () if ___________ [ ___ ] == ‘>’: print(_____________ ) count ______________ 1 print( _________ )Think about a class for representing times during a day’s 24 hours. Answer the following questions develop this class.[18 pts]What would be the instance variables for time [3]? What would be appropriate getter functions [3] ?Describe 6 useful functions besides the getters [12]. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download