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 /
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
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,[econom
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
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 repre
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=
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
An
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,
Georg
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]
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 t