COSC 1306

Name: ____________________________________ (First name first)
COSC 1306 FIRST REVIEW SEPTEMBER 25, 2013 Closed book. You are allowed a single 8.5"×11" one‐sided sheet of notes. UH expels cheaters. 1. Complete the following sentences:
Running programs reside in the _________________________________________ of the computer. GUI stands for _____________________________________________________________. 2. You are going to the University Center with a nerd who claims he has an algorithm for finding out what
is the best available flavor at the ice cream shop. Can you guess his algorithm?
3. Describe a practical heuristic for the same problem. Why is it a heuristic?
4. What is probably wrong with the following Python program? Can you correct it??
nfingers = input(“How many fingers do you have?”) if nfingers != 20 : print(“Did you lose some in an accident?”) 5.
What will the following Python program print?
code = 5 if code == 1 print(“Hello!”) print(“Goodbye!”) 1
6.
What is wrong with the following Python code?
i = 1 while i > 0 : print(“Going though the loop!”) i = i + 1 7. What are the values of the variables a, b, c, d after the following Python code is executed?
a = 4 * 2 – 0.5 b = 2 c = a // b d = a == c a = ___________ b = ___________ c = ___________ d = __________ 8. Write a Python program asking for your first and last name and printing out Hello J. Doe! as in
Enter your first name: John Enter your last name: Doe Hello J. Doe! 9. Write a Python function that computes
a 2 + b2 given the two parameters a and b.
2
10. Write a Python program that reads an integer and computes and prints if it is a Prime or Not
Prime.
11. Write a Python function that proceeds as follows. First it takes Today’s date as input. Then it repeatedly:
requests the Date of Birth of a customer and prints “OK TO SERVE ALCOHOL” or “DO NOT SERVE
ALCOHOL” depending on whether the customer’s age is 18 or higher. For entering a date, a separate
prompt is given for Year, Month and Day, each entered as a number.
3