Finally, we can meet again in my blog friends, I’m happy to meet you. I just want to share what I know about Python Programming Language. Actually I need your comments about my writing especially for you who are master of Python Programming Language. Although my writing is not perfect, but I hope it is useful for you especially for newbie to learn about Python Programming Language. At least, you can know about what the bases of Python Programming Language. I will began this material below :
This material discuss about how programmer write codes so that users can input a value and the value can be processed by Python.
What kind of this function to do it ?Python provides input or raw_input function. For Python with version 3 up is using input whereas Python with version 3 down is using raw_input.How to use this ?Example : ( I use Python version 2.7)a = raw_input(“Your statement : ‘string’”)
print a It will print string which filled by users.
Note : in formula above, string will be filled by users not programmer, so let it be empty.
See the example below :
Why I use “+” when joining var a and var b with the string ?Because it is right that joining between string and string on Python using “+” . It is different when we will join between integer and string. It will be learned after this. Let’s we continue this first my friends.Then, user must fill or input string. See the Interactive Mode of the program above after executing :
Need to know when you write script after print, if something that you print is string or statement, the string must use quotes (“ “ ). But if something that you print is variable, you don’t need using quotes (“ “).
The next material is inputting integer and the value will be joined with string.What’s the meaning ?I will explain it to you. For example, user is asked by a program like this “How many your ages?” it means that user is asked to input integer. You still remember right my writing that I had written before about Learning about Bases of Python Programming Language for Newbie. I believe that you still remember, hehe.. We back to our topics, so how programmer should write scripts so that user can input integer ? the answer is converting from string into integer. Then, how ?On the first material, we have written :a = raw_input(“Your statement : ‘string’”) Now, to convert string into integer , we should add int in the behind of raw_input. Just see the formula below :a = int(raw_input(“Your statement : ‘integer’”))
print aDon’t forget to write double closing bracket in the behind because there are two opening brackets. Many people who forget about that.
And the next topic is how to join string with integer. We should use comma (,) between string and integer.See the example below :
The Interractive Mode of the program above after executing :
OK, the last topics if we convert from string into float.The writing is almost same with converting string into integer. See the formula below :a = float(raw_input(“Your statement : ‘float’”))
print aThe function is when you want user input decimal number. For example, you ask user like this “How tall you are ? “ in this case, user must input decimal number.See the example below :
The interactive Mode of the program after executing :
It is easy right ? heheIt will be easy if you have hard intention to learn programming language. This is base of Python learning friends. You need to learn more and more to be expert programmer. That’s all for today, and wait for my next writing.
Thanks for your visiting