ThatPythonNoob ThatPythonNoob - 1 year ago 79
Python Question

print statement inside of input returns with a "none"

I am working on a little program and I want to use:

ans = int(input(print(multi,'x',num,'=')))

This works well except for the fact that after it prints the print statement it says none. like:

49 x 7 =

How would on remove the "none" if possible? Also I did search this problem but nothing was about returning a none inside of an input.

Answer Source

input takes a prompt string as its argument, which it will print automatically, but print returns None; it is this that gets printed by input. Your code is equivalent to:

prompt = print(...) # prompt == None
ans = int(input(prompt)) 

Instead, use str.format to build the prompt and pass it straight to input:

ans = int(input('{0}x{1}='.format(multi, num)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download