You all should know by now that you can use the "raw_input" command to take in what the user inputs. I'm also sure you all know about the very similar command "input". however, what I think some of you guys are not so sure about is what "input" actually does. Well, I shall explain that right now!
The command "input" is used to take in the user's input but the input is not treated as a string of characters; it is treated as a line of code. For example, when we had the calculator assignment, we went through the process of typing out long and various amounts of code in order to perform each individual function. However, if you were to type the code below into Python, you'll see that you can actually get the answer with only a few lines of code!
def Test():
Answer = input("Please insert your first number followed by the equation symbol followed by the second number you wish to perform a calculation on: ")
print str(Answer)
Test()
Once you have typed this out into Python, save it and run it. After you have done that, input the line "1+1" and hit 'enter'. You should see that the answer is displayed!
This was originally taught to me by Adam and its quite useful to know! Keep note of it!
So far I don't see any python happening but I know when it does it will be special.
ReplyDeleteUpdate: Great python example.
DeleteLooks great, I can see alot of stuff happening here
ReplyDelete