Select the correct answerWhat will be the output of the following Python code?def example(c, m): while m > 0: print(c,end="") m=m-1example('q',3)OptionsqqqqqAn exception is executedInfinite loop
Question
Select the correct answerWhat will be the output of the following Python code?def example(c, m): while m > 0: print(c,end="") m=m-1example('q',3)OptionsqqqqqAn exception is executedInfinite loop
Solution
The correct answer is "qqq". The function "example" takes two arguments, a character 'c' and a number 'm'. It then enters a while loop that continues as long as 'm' is greater than 0. In each iteration of the loop, it prints the character 'c' without a newline (due to the end="") and then decreases 'm' by 1. So if we call example('q',3), it will print 'q' three times, resulting in "qqq".
Similar Questions
Select the correct answerWhat will be the output of the following Python code?def demo(p,q): if(p == 0): return q else: return demo(p-1,p+q)print(demo(4,5))Options513Infinite loop15
Select the correct answerWhat will be the output of the following Python code?def p(q): q = q + [5] r = [1, 2, 3, 4]p(r)print(len(r))Options451An exception is thrown
Select the correct answerWhat will be the output of the following Python code?def p(num): if num == 0: return 0 elif num == 1: return 1 else: return p(num-1)+p(num-2)for k in range(0,4): print(p(k),end=" ")OptionsAn exception is thrown 0 1 2 30 1 1 2 30 1 1 2
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?def example(k = 1, l = 2): k = k + l l = l + 1 print(k, l)example(l = 1, k = 2)Options1 2An exception is thrown because of conflicting values3 33 2
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.