Select the correct answerWhat is the output of the following program : p = 2while (p < 9): print(p) p-- print (p+4)OptionsError2 1 0 -1 -22 6 2 6 22 3 4 5 6
Question
Select the correct answerWhat is the output of the following program : p = 2while (p < 9): print(p) p-- print (p+4)OptionsError2 1 0 -1 -22 6 2 6 22 3 4 5 6
Solution
The correct answer is "Error".
The reason is that in Python, there is no "--" operator to decrement the value of a variable. Instead, you should use "-=" operator. So, the correct code should be:
p = 2 while (p < 9): print(p) p -= 1 print (p+4)
The "--" operator is causing a syntax error in this case.
Similar Questions
What is the output of the following?ct = 2while True: if ct % 0O6 == 0: break print(ct) ct += 1Options2345error.None of these2 3 4 5 6
= 0while i < 5: if i == 2: i += 1 continue else: print(i,end = " ") i += 1Options: Pick one correct answer from below0 1 2 3 40 1 3 4Runtime Error1
Select the correct answerWhat will be the output of the following Python program?i = 0while i < 5: print(i) i += 1 if i == 3: breakelse: print(0)Options0 1 20 1 2 0errornone of the mentioned
Select the correct answerWhat will be the output of the following Python code snippet?c = 2for t in range(c): c -= 2 print (c)Optionserror00-201234 …
What will be the output of the following Python code?k = 1while k < 6: print(k) k += 1 if k == 4: breakelse: print(0)Options0 1 2 3 0 errornone of the mentioned1 2 3
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.