Download presentation
Presentation is loading. Please wait.
Published byPreston Barnett Modified over 8 years ago
1
SOLUTIONS TO THE QUESTIONS DISCUSSED DURING THE FIRST REVIEW SESSION COSC 1306 Fall 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 = 5 while 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 = 25 : s = “ Can drink alcohol”
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.