Select the correct answerWhat is the output of the following program : p = 2while (p < 9): print(p) p-- print (p+4)Options2 1 0 -1 -22 6 2 6 2Error2 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)Options2 1 0 -1 -22 6 2 6 2Error2 3 4 5 6
Solution
The correct answer is "Error".
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)
If you run the original code, it will give you a syntax error.
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
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
= 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
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
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 …
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.