Python questions for a study guide, help would be appreciated, thank you. ______
ID: 3585052 • Letter: P
Question
Python questions for a study guide, help would be appreciated, thank you.
______________________________________________________________________
1.) What string is stored in b after the following code executes:
a = 'The quick brown fox jumped over the lazy dog."
b = a[1:3]
2.)What is the output from the following print statement?
print("The temperature is currently %d degrees in %s, %s." % (78, "New York", "NY"))
3.) The condition for a while loop must equate to a boolean value. True or False?
4.) An elif statement requires a condition. True or False?
5.) An else statement requires a condition. True or False?
6.) Rewrite the following for loop as a while loop:
nums = [10, 15, 20, 25]
total = 0
for num in nums:
total += num
7.) Rewrite the following while loop into a for loop:
i = 0
while i < 10:
print(i)
i += 1
8.) What type of loop should you use when the number of iterations are not computable before entering the loop?
9.) What type of loop is best suited to access the elements of a container?
10.) What does a break statement do?
11.) What does a continue statement do?
12.) A loop else clause is executed only when the loop terminates normally. True or False?
Explanation / Answer
1)The operator [n:m] returns the part of the sequence from the n’th element to the m’th element, including the first but excluding the last.
so, the string is stored in b 'he'
2) output is : The temperature is currently 78 degrees in New York, NY.
3)Syntax of Python while loop
so, the answer is False
4) syntax
So, The answer is True.
5)syntax
So, The answer is False.
6)while True
if num in nums
total+=num
7)for i in range(0,10):
print(i)
i += 1
8)do-while loop
9)for loop
10)It terminates the current loop and resumes execution at the next statement.
11)It returns the control to the beginning of the while loop.
12)False
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.