22c:080
Chapter 5 Practice Problems
5.1
Implement function myBMI() that takes as input a persons height and weight and computes the
persons BMI
Solution:
def myBMI(weight, height):
bmi = weight*703 / height*2
if bmi < 18.5:
print(underweight)
elif bmi < 2
22c:080
Chapter 2 Practice Problems
2.1
Write Python algebraic expressions:
a. the sum of the first 5 positive integers
b. the average age of sara(23), mark(19), and fatima(31)
c. the number of times 73 goes into 403
d. the remainder of 403 divided by 73
22c:080
Chapter 11
11.1
Write method news() that takes a URL of a news web site and a list of news topics and computes
the number of occurrences of each topic in the news
>news(http:/bbc.co.uk,[economy,climate,education]
Economy appears 3 times
Climate ap
22c:080
Chapter 10
10.1
Implement a recursive method reverse() that takes a nonnegative integer as input and prints the
digits of n vertically, starting with the low-order digit:
>reverse(3124)
4
2
1
3
Solution:
Def reverse(n):
If n <10:
Print(n)
Else:
Pr
22c:080
Chapter 8
8.1
Add method getx() to the class Point: this method takes no input and returns the xcoordinate
Solution:
Def getx(self):
Return self.xcoord
8.3
Implement class Rectangle that represents rectangles. The class should support the methods:
22c:080
Chapter 7
7.2
For each name in the module, indicate whether it is a global name or whether it is local in f(x) or
local in g(x):
Def f(y):
X=2
Return g(x)
Def g(y):
Global x
X =4
Return x*y
X=0
Res = f(x)
Print(x = cfw_, f(0) = cfw_.format(x,res)
22c:080
Chapter 1 Notes
Computer Science
What do computer professionals do?
o Fields:
Defense
Driving
Education
Farming
Films
Medicine
Media
Physics
Politics
Shopping
Space exploration
And more
Models, Algorithms, and Programs
o Model: abstr
22c:080
Chapter 6
6.1
Write a function birthState() that takes as input the full name of a recent U.S. prudent and returns
his birth state. Use this dictionary:
cfw_Barack Hussein Obama: Hawaii,
George Walker Bush: Connecticut,
William Jefferson Clinton:
22c:080
Chapter 4 practice problems
4.1
s = 0123456789
Write expressions using string s and the indexing operator that evaluate to:
a. 234
b. 78
c. 1234567
d. 0123
e. 789
Solutions
a. s[2:5]
b. s[7:9]
c. s[1:8]
d. s[:4]
e. s[7:]
4.2
Assuming the variable
22c:080
Chapter 3 practice problems
3.1
Implement a program that asks for the current temperature in degrees Fahrenheit and prints the
temperature in degrees Celsius
Solution
Fahr = eval(input(Enter the temperature in degrees Fahrenheit: )
Cels = (fahr 32