Jun-15-2018, 02:23 PM
(Jun-15-2018, 01:13 PM)buran Wrote: On the other hand python3 usesinput
, while python2 equivalent israw_input
, so I'm not 100% your book is for python2. If it is python2 book and teaches you to useinput
in python2, it's a poor textbook, definitely don't use it.
In Python2,
input
exists too - but it evaluates the entered expression, that's what would have allowed OP to multiply without conversion.Python2
input
would return number - if number is entered - due to expression evaluation. Unfortunately, it would allow to execute a valid Python command, if entered - the reason why it (input
) is considered dangerous, and its usage discouraged.raw_input
in Python2 returns stringSo the book is definitely Python2 - and also correct, though uses discouraged practice.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.