DOC PREVIEW
TAMU CSCE 110 - sample-questions
Type Miscellaneous
Pages 4

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSCE 110: Programming ISample Questions for Exam #3November 22, 2011Below are sample questions to help you prepare for Exam #3. Make sure you can solve allof these problems by hand. For most of the questions, you can check your answers by typingin the programs and seeing what happens on the computer. When writing your programs byhand, please write clearly and make sure that the indenting of your program is clear.1. Consider the following Python program.1 fruits = [’ cherry ’, ’ pecan ’, ’ apple ’]2 print [ fruit + ’ pie ’ for fruit in fruits ] # Li n e A3 vec = [2 , 4, 6]4 print [3* x for x in vec ] # Li n e B5 print [3* x for x in vec if x > 3] # Li n e C6 print [[x ,x **2] for x in vec ] # Li n e D7 vec1 = [2 , 4 , 6]8 vec2 = [4 , 3 , -9]9 print [ x * y for x in vec1 for y in vec2 ] # Li n e E10 print [ vec1 [i ]* vec2 [i] for i in range ( len ( vec1 ))] # Li n e F What is the output?2. Consider the following Python program.1 def f( v1 , v2 = ’ Happy Thanksg i ving ! ’ ):2 return [v1 , v2 ]34 print f (5) # Li n e A5 print f ( v2 = ’ Merry Christmas ! ’, v1 = 3) # Li n e B6 print f ( v2 = 3) # Li n e C7 print f (9 , 10) # Li n e D8 print f ( v1 = 20) # Li n e E9 print f ( v3 = 7) # Li n e F What is the output? If a line causes an error, write ERROR as the output of that line. Also,explain why the error is produced.13. Consider the following Python program.1 n = 102 def f1 ():3 m = 34 def f2 ():5 n = 46 print m + n7 print m89 def f3 ():10 print m + n1112 f2 ()13 f3 ()14 f1 ()15 print ’ Done ! ’ a) What is the output?b) For each function, list each of its local variables and the line number(s) in which the localvariables appear.c) List all of the global variables that appear in the program and the line numbers in whichthey appear.4. Suppose you know the following portion of the ASCII table.• ’A’ is 65.• ’B’ is 66.• ’a’ is 97.• ’b’ is 98.Now, write out the binary representation for the word ’Apple’. Do this calculation based onwhat you know about the ASCII table and what’s given above.5. Consider the following Python program.1 myDict = {}2 myList = [1 ,2 ,3 ,4 ,5]3 myStr = ’abcde ’4 cnt = 056 for c in myStr :7 myDict [ c ]= sum ( myList [ cnt :])8 cnt += 19 print myDict [ ’b ’] # L i n e A10 print cnt # Li n e B11 print " Testing : " , myDict . items () # L i n e C1213 for key , val in myDict . items ():14 if val %2 == 0:15 myDict [ key ] = val /216 print myDict [ ’b ’] # L i n e D17 print " Testing2 : " , myDict . items () # L i n e E 2a) What output does Line A produce?b) What output does Line B produce?c) What output does Line C produce?d) What output does Line D produce?e) What output does Line E produce?6. Convert the decimal number 186 to its binary and hexadecimal representations.7. Convert the hexadecimal value 8FF3A0 to binary and decimal numbers.8. Write a program that asks a user to enter a binary number (or string). Now, tell the userwhether their binary number is even or odd.a) One way to solve this problem is to convert the binary number to decimal, and thendetermine if the decimal number is even or odd.b) However, for this problem, do not convert the binary number to decimal. By analyzingthe binary string, you should be able to determine whether the number it represents iseven or odd.9. There are 36 possible combinations of two dice (die 1 and die 2). Write a program thatuses a dictionary to create a table that produces the sum of two dice and all of the possiblecombinations that are possible for that sum. Below is an example of the table that yourprogram should create.Total Frequency (%) Combinations2 2.8 [(1, 1)]3 5.6 [(1, 2), (2, 1)]4 8.3 [(1, 3), (2, 2), (3, 1)]5 11.1 [(1, 4), (2, 3), (3, 2), (4, 1)]6 13.9 [(1, 5), (2, 4), (3, 3), (4, 2), (5, 1)]7 16.7 [(1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1)]8 13.9 [(2, 6), (3, 5), (4, 4), (5, 3), (6, 2)]9 11.1 [(3, 6), (4, 5), (5, 4), (6, 3)]10 8.3 [(4, 6), (5, 5), (6, 4)]11 5.6 [(5, 6), (6, 5)]12 2.8 [(6, 6)]For example, for two dice that sum to 5, there is an 11.1% chance of this outcome occurring.Moreover, for a dice sum of 5, there are 4 different possibilities.• die 1 = 1, die 2 = 4• die 1 = 2, die 2 = 3• die 1 = 3, die 2 = 2• die 1 = 4, die 2 = 110. Redo Question #9. This time use the array data structure in numpy to create a table thatproduces the sum of two dice and all of the possible combinations that are possible for thatsum.311. Assume you have a list of words, where each word is of length 5. (Use the 5-letter-words.txtfile from Lab #10.) Ask the user to enter a sequence of vowels (for example, a, e, and i).Now, write to the file output-words.txt all of the words that only contain the vowels a, e,and i in that order. Consonants can separate the vowels.Here’s an example. First, ask the user for a sequence of vowels. Also, output the numberof words that were printed to the output-words.txt file.1 Please enter a string of vowels : aei2 Number of words printed in output - words . txt : 3 Below, are the contents of the wordplay-output.txt file.1 aegis2 areic3 naevi You should try to write this program in the fewest number of lines possible (which mustinclude comments and user-defined functions). A lot of code can be difficult to manage.12. Write down the specifications of your home computer. How much memory do you have? Howlarge is your hard drive? Do you have a 32 or 64-bit processor. Is your processor Intel, AMD,or something else? What operating system do you use? Now, compare your computer to thespecifications of the machines in the


View Full Document

TAMU CSCE 110 - sample-questions

Type: Miscellaneous
Pages: 4
Documents in this Course
06-IO

06-IO

29 pages

21-OOP

21-OOP

8 pages

key

key

6 pages

21-OOP

21-OOP

8 pages

Load more
Download sample-questions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view sample-questions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view sample-questions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?