Find the output of the following Python Code: def PatternLogic(N): for C in…

2026

Find the output of the following Python Code:

def PatternLogic(N):
for C in range(1, N + 1):
Line = ""
if C % 2 == 0:
Line = str(C) + ("#" * C)
else:
Line = str(C) + ("*" * C)
if C != 3:
print(Line)

Num = 4
PatternLogic(Num)
print("Process Complete")

Show answer & explanation
  • Function PatternLogic(N) runs a loop from 1 to N (i.e., 1 to 4).

  • For odd values, it prints number followed by * repeated C times.

  • For even values, it prints number followed by # repeated C times.

  • Condition if C != 3 skips printing when C = 3.

  • Iterations:

    • C=1 ⇒ 1*

    • C=2 ⇒ 2##

    • C=3 ⇒ skipped

    • C=4 ⇒ 4####

  • After function execution, "Process Complete" is printed.

  • Final Output:

    1*
    2##
    4####
    Process Complete

Explore the full course: Hpsc Pgt Computer Science