Ch. 2 Flashcards
Writing Sample Programs
list and describe the six steps in software development process
plan, design, develop, test, deploy, maintain
explain the relationship among the concepts definite loop, for loop, and counted loop
def loop- Used to repeat a block of code a number of times. The number of iterations is known in advance.
for loop- continues to execute as long as the condition is true.
counted loop- relies on a counter variable
show the output from the following fragments:
for i in range (5):
print(i*i)
- i range is 0,1,2,3,4
- go through for loop using i
a. 0 0
b. 11
c. 22
d. 33
e. 4*4 - output:
0
1
4
9
16
for d in [3,1,4,1,5]:
print(d, end=” “)
- [ ] means list
- 3 gets printed
- bc end= “ “, the following numbers will get printed next to each other
- output: 3 1 4 1 5
for i in range(4):
print(“Hello”)
- range is 0,1,2,3
- Hello is printed 4 times
- output:
Hello
Hello
Hello
Hello
for i in range(5):
print(i, 2**i)
- ** means to the power of
- range is 0,1,2,3,4
- outcome:
0 1
1 2
2 4
3 8
4 16
why is it a good idea to first write out pseudocode rather than to python code first
helps to plan and organize
what does sep parameter do
print(“apple”, “banana”, sep=’-‘)
Prints “apple-banana”
what will happen:
print(“start”)
for i in range(0):
print(“Hello”)
print(“end”)
start
end
“hello” doesn’t print because a number between 0 and 0 doesn’t exist
write a program that converts fahrenheit to celsius
celsius = eval(input(“enter celsius”))
fahrenheit = 9/5 * celsius + 32
print(“celsius in fahrenheit is”, fahrenheit)
write a program that converts distances measured in kilometers to miles. one kilometer is approx .62 miles
kilometers = eval(input(“enter kilometers “))
miles = kilometers * .62
print(kilometers, “kilos in miles is”, miles)
write an interactive python calculator program
null