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 =
None

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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)))


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x