Chapter02 Python Programming
Chapter02 Python Programming
An Introduction to
Computer Science
Chapter 2
Writing Simple Programs
def main():
celsius = eval(input("What is the Celsius temperature? "))
fahrenheit = (9/5) * celsius + 32
print("The temperature is ",fahrenheit," degrees Fahrenheit.")
main()
expressions.
Successive print statements will display on
separate lines.
A bare print will print a blank line.
0
1
2
3
>>> for odd in [1, 3, 5, 7]:
print(odd*odd)
1
9
25
49
>>>
def main():
print("This program calculates the future value of a 10-year investment.")
for i in range(10):
principal = principal * (1 + apr)
main()