1 / 11

SOLUTIONS TO THE QUESTIONS DISCUSSED DURING THE FIRST REVIEW SESSION

SOLUTIONS TO THE QUESTIONS DISCUSSED DURING THE FIRST REVIEW SESSION. COSC 1306 Fall 2013. First question. Main memory Graphical user interface. Second and third questions. Algorithmic approach: Try all flavors in sequence. It always works. Heuristics:

trang
Download Presentation

SOLUTIONS TO THE QUESTIONS DISCUSSED DURING THE FIRST REVIEW SESSION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SOLUTIONS TO THE QUESTIONS DISCUSSED DURINGTHE FIRST REVIEW SESSION COSC 1306Fall 2013

  2. First question • Main memory • Graphical user interface

  3. Second and third questions • Algorithmic approach: • Try all flavors in sequence. It always works. • Heuristics: • Picking the tub that has the least ice cream. • Trying a a few likely winners.

  4. Fourth question • We cannot compare a string to a number

  5. Fifth Question • It will not work • Missing column athe end of the if

  6. Sixth question • Will loop forever • Should be:i= 5while i> 0 :i= i -1 or I -= 1 • Use for I in range(…) instead

  7. Seventh question • a = 7.5 • b = 2 • c = 3.0 • d = False

  8. Eighth question """ Eighth Question""" first = input("Enter your first name: ") second = input("Enter your last name: ") print("Hello " + first[0] + ". " + second + "!")

  9. Ninth question from math import sqrt def norm(a, b) : return sqrt(a*a + b*b) print(norm(3, 4)) will print 5.0

  10. Tenth question from math import sqrt number = int(input("Enter an integer: ")) s= "This number is prime" biggest = int(sqrt(number)) for i in range(2, biggest + 1) : if (number % i == 0) : s = "This number is not prime" print(s) This solution wastes cycles: we should exit the loop as soon as we find out that the number is not prime!

  11. Eleventh question • Something like: s = “Cannot drink alcohol”if birthyear < 1995 : s = “ Can drink alcohol”elifbirthyear == 1995 : if birthmonth < 9 : s = “ Can drink alcohol”elifbirthmonth == 9 and birthday >= 25 : s = “ Can drink alcohol”

More Related