Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

CPSC 231: Extra midterm review questions Multiple choice questions 1. The UNIX command ________ could be used to see the contents of a file. a. cd b. ls c. more d. see e. None of the above commands would allow you to view a file. 2. In terms of a Python program which of the following...

CPSC 231: Extra midterm review questions Multiple choice questions 1. The UNIX command ________ could be used to see the contents of a file. a. cd b. ls c. more d. see e. None of the above commands would allow you to view a file. 2. In terms of a Python program which of the following is true about the variable ‘num’ in the program below? num = 3.14 a. num is a floating point variable b. num is an integer variable c. num is a real number variable d. num is a string variable e. The type of information associated with variable num cannot be determined solely from the above program 3. What will be the output of the following program? name = input ("Type in your name: ") print("Name:", name) a. Name name b. Name: name c. Name: James Tam d. Name: James Bond e. None of the above selections correctly and completely characterize the output 4. Which operator is used for finding the remainder of a division operation? a. * b. % c. exp() d. exponent() e. None of the above How many times will the loops in Question 5 - 7 execute 5. i = 1 while (i > Question 2: What’s the output of the following program? x = "sheen" y = 51 z = 1/3 print("%d\nd\t%s" %(-7,"miley")) print("\\%6s\'-4%-3d%.2f" %(x,y,z)) > > Question 4: Canada employs a ‘progressive tax’ system (primary source: http://www.cra- arc.gc.ca/tx/ndvdls/fq/txrts-eng.html). The following is a modification of the actual tax system. If $10,822 or less then you pay no income tax. Income over $10,822 up to and including 43,561 is taxed at 15%. For income more than $43,561, but not more than $87,123, the tax rate is 22%. For income more than $87,123, but not more than $135,054, the tax rate is 26%. For income is more than $135,054, the tax rate is 29%. For the purposes of this question a person will only be classified into one of the above tax brackets e.g., a person earning $100,000 pays a 26% tax rate. Modify the program below so that it calculates and displays: the amount of tax owed and income after taxes have been deducted. grossIncome = 0 taxesOwed = 0 incomeAfterTaxes = 0 grossIncome = int(input("Enter your yearly income: ")) (Write you answer on the next page, on an actual exam you could use the above space for rough work). > > incomeAfterTaxes = grossIncome - taxesOwed print("Gross income $%d" %grossIncome) print("" %taxesOwed) print("Income after taxes $%d" %incomeAfterTaxes) Question 5: (From the University of Calgary calendar 2012 - 2013 Page 338). The prerequisites for CPSC 331 are the following: “One of Computer Science 219, 233, 235 [JT: the calendar includes Computer Engineering 339 but for simplicity you can exclude it from this question] and one of Mathematics 271 or 273”. Modify the following program so that the message “pre-requisites met” appears if the student has taken the appropriate course and the message and the message pre-requisites not met” otherwise. You can assume that the course information will come in as a string: Computer Science courses will be abbreviated as CPSC, math courses abbreviated as MATH. The format will be as follows e.g. CPSC 231 cpscCourseTaken = input("What Computer course have you taken: ") mathCourseTaken = input("What Math course have you taken: ") Write you answer on the next page, on an actual exam you could use the above space for rough work). >

Use Quizgecko on...
Browser
Browser