Why I am getting a special character printed after the recursive DFS?

Viewed 46

I have a simple toy code for Depth First Search, But why I am getting a % after the print?

# Definition for a  binary tree node
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None
    def dfs(t):
    if t==None:    
        print("",end="")    
    else:    
        print(t.val,end="")        
        dfs(t.left)        
        dfs(t.right)

t=TreeNode(1)
t.left=TreeNode(2)
t.right=TreeNode(3)
t.left.left=TreeNode(4)
t.left.right=TreeNode(5)
t.right.left=TreeNode(6)
t.right.right=TreeNode(7)
dfs(t)

Output: 1245367%

1 Answers

That's your shell prompt. Your output doesn't end with a line terminator, so your shell prints its "next command, please" prompt on the same line as your program's output.

Related