Ch. 2 Flashcards

Writing Sample Programs

1
Q

list and describe the six steps in software development process

A

plan, design, develop, test, deploy, maintain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

explain the relationship among the concepts definite loop, for loop, and counted loop

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

show the output from the following fragments:
for i in range (5):
print(i*i)

A
  1. i range is 0,1,2,3,4
  2. go through for loop using i
    a. 0 0
    b. 1
    1
    c. 22
    d. 3
    3
    e. 4*4
  3. output:
    0
    1
    4
    9
    16
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

for d in [3,1,4,1,5]:
print(d, end=” “)

A
  1. [ ] means list
  2. 3 gets printed
  3. bc end= “ “, the following numbers will get printed next to each other
  4. output: 3 1 4 1 5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

for i in range(4):
print(“Hello”)

A
  1. range is 0,1,2,3
  2. Hello is printed 4 times
  3. output:
    Hello
    Hello
    Hello
    Hello
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

for i in range(5):
print(i, 2**i)

A
  1. ** means to the power of
  2. range is 0,1,2,3,4
  3. outcome:
    0 1
    1 2
    2 4
    3 8
    4 16
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

why is it a good idea to first write out pseudocode rather than to python code first

A

helps to plan and organize

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what does sep parameter do

A

print(“apple”, “banana”, sep=’-‘)
Prints “apple-banana”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what will happen:

print(“start”)
for i in range(0):
print(“Hello”)
print(“end”)

A

start
end
“hello” doesn’t print because a number between 0 and 0 doesn’t exist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

write a program that converts fahrenheit to celsius

A

celsius = eval(input(“enter celsius”))
fahrenheit = 9/5 * celsius + 32
print(“celsius in fahrenheit is”, fahrenheit)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

write a program that converts distances measured in kilometers to miles. one kilometer is approx .62 miles

A

kilometers = eval(input(“enter kilometers “))
miles = kilometers * .62
print(kilometers, “kilos in miles is”, miles)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

write an interactive python calculator program

A

null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly