Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Power Lifting Lever Belt
SkullVamp
Updated:
Saturday at 10:32 PM
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Saturday at 3:55 PM
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Thursday at 2:23 PM
Ad icon
Wechat qr verification
Pawan2005
Updated:
Thursday at 1:28 AM
🚀 GOOGLE AI PRO 18 MONTHS ACTIVATION 🚀
sayuru bandara
Updated:
Wednesday at 5:34 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
Python The Worlds Most flexible and easist Language..
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="gayan kalhara" data-source="post: 3307483" data-attributes="member: 60168"><p><strong>Hello, World</strong></p><p></p><p style="text-align: center"><strong>2.1 What you should know</strong></p> <p style="text-align: center"></p><p></p><p>You should know how to edit programs in a text editor or IDLE, save them to disk (floppy or hard) and run them once</p><p>they have been saved.</p><p style="text-align: center"><strong> 2.2 Printing</strong></p> <p style="text-align: center"></p><p></p><p>Programming tutorials since the beginning of time have started with a little program called Hello,World! So here it is:</p><p></p><p>print "Hello, World!"</p><p></p><p>If you are using the command line to run programs then type it in with a text editor, save it as ‘hello.py’ and run it with</p><p>“python hello.py”</p><p>Otherwise go into IDLE, create a new window, and create the program as in section 1.4.</p><p>When this program is run here’s what it prints:</p><p></p><p>Hello, World!</p><p></p><p>Now I’m not going to tell you this every time, but when I show you a program I recommend that you type it in and run</p><p>it. I learn better when I type it in and you probably do too.</p><p></p><p>Now here is a more complicated program:</p><p></p><p>print "Jack and Jill went up a hill"</p><p>print "to fetch a pail of water;"</p><p>print "Jack fell down, and broke his crown,"</p><p>print "and Jill came tumbling after."</p><p></p><p>When you run this program it prints out:</p><p>Jack and Jill went up a hill</p><p>to fetch a pail of water;</p><p>Jack fell down, and broke his crown,</p><p>and Jill came tumbling after.</p><p></p><p></p><p>When the computer runs this program it first sees the line:</p><p>print "Jack and Jill went up a hill"</p><p>so the computer prints:</p><p>Jack and Jill went up a hill</p><p>Then the computer goes down to the next line and sees:</p><p>print "to fetch a pail of water;"</p><p>So the computer prints to the screen:</p><p>to fetch a pail of water;</p><p>The computer keeps looking at each line, follows the command and then goes on to the next line. The computer keeps</p><p>running commands until it reaches the end of the program.</p><p></p><p style="text-align: center"> <strong>2.3 Expressions</strong></p> <p style="text-align: center"></p> <p style="text-align: center"></p> <p style="text-align: center"></p><p>Here is another program:</p><p>print "2 + 2 is", 2+2</p><p>print "3 * 4 is", 3 * 4</p><p>print 100 - 1, " = 100 - 1"</p><p>print "(33 + 2) / 5 + 11.5 = ",(33 + 2) / 5 + 11.5</p><p>And here is the output when the program is run:</p><p>2 + 2 is 4</p><p>3 * 4 is 12</p><p>99 = 100 - 1</p><p>(33 + 2) / 5 + 11.5 = 18.5</p><p></p><p>As you can see Python can turn your 50 thousand RS computer into a 150 RS calculator.</p><p></p><p>Python has six basic operations:</p><p>Operation Symbol Example</p><p>Exponentiation ** 5 ** 2 == 25</p><p>Multiplication * 2 * 3 == 6</p><p>Division / 14 / 3 == 4</p><p>Remainder % 14 % 3 == 2</p><p>Addition + 1 + 2 == 3</p><p>Subtraction - 4 - 3 == 1</p><p>Notice that division follows the rule, if there are no decimals to start with, there will be no decimals to end with. (Note:</p><p>This will be changing in Python 2.3) The following program shows this:</p><p></p><p>4 Chapter 2. Hello, World</p><p></p><p>print "14 / 3 = ",14 / 3</p><p>print "14 % 3 = ",14 % 3</p><p>print</p><p>print "14.0 / 3.0 =",14.0 / 3.0</p><p>print "14.0 % 3.0 =",14 % 3.0</p><p>print</p><p>print "14.0 / 3 =",14.0 / 3</p><p>print "14.0 % 3 =",14.0 % 3</p><p>print</p><p>print "14 / 3.0 =",14 / 3.0</p><p>print "14 % 3.0 =",14 % 3.0</p><p>print</p><p>With the output:</p><p>14 / 3 = 4</p><p>14 % 3 = 2</p><p>14.0 / 3.0 = 4.66666666667</p><p>14.0 % 3.0 = 2.0</p><p>14.0 / 3 = 4.66666666667</p><p>14.0 % 3 = 2.0</p><p>14 / 3.0 = 4.66666666667</p><p>14 % 3.0 = 2.0</p><p></p><p>Notice how Python gives different answers for some problems depending on whether or not there decimal values are</p><p>used.</p><p></p><p>The order of operations is the same as in math:</p><p>1. parentheses ()</p><p>2. exponents **</p><p>3. multiplication *, division \, and remainder %</p><p>4. addition + and subtraction -</p><p></p><p style="text-align: center"> <strong>2.4 Talking to humans (and other intelligent beings)</strong></p> <p style="text-align: center"></p><p></p><p>Often in programming you are doing something complicated and may not in the future remember what you did.</p><p>When this happens the program should probably be commented. A comment is a note to you and other programmers</p><p>explaining what is happening. For example:</p><p>#Not quite PI, but an incredible simulation</p><p>print 22.0/7.0</p><p>Notice that the comment starts with a #. Comments are used to communicate with others who read the program and</p><p>your future self to make clear what is complicated.</p></blockquote><p></p>
[QUOTE="gayan kalhara, post: 3307483, member: 60168"] [b]Hello, World[/b] [CENTER][B]2.1 What you should know[/B] [/CENTER] You should know how to edit programs in a text editor or IDLE, save them to disk (floppy or hard) and run them once they have been saved. [CENTER][B] 2.2 Printing[/B] [/CENTER] Programming tutorials since the beginning of time have started with a little program called Hello,World! So here it is: print "Hello, World!" If you are using the command line to run programs then type it in with a text editor, save it as ‘hello.py’ and run it with “python hello.py” Otherwise go into IDLE, create a new window, and create the program as in section 1.4. When this program is run here’s what it prints: Hello, World! Now I’m not going to tell you this every time, but when I show you a program I recommend that you type it in and run it. I learn better when I type it in and you probably do too. Now here is a more complicated program: print "Jack and Jill went up a hill" print "to fetch a pail of water;" print "Jack fell down, and broke his crown," print "and Jill came tumbling after." When you run this program it prints out: Jack and Jill went up a hill to fetch a pail of water; Jack fell down, and broke his crown, and Jill came tumbling after. When the computer runs this program it first sees the line: print "Jack and Jill went up a hill" so the computer prints: Jack and Jill went up a hill Then the computer goes down to the next line and sees: print "to fetch a pail of water;" So the computer prints to the screen: to fetch a pail of water; The computer keeps looking at each line, follows the command and then goes on to the next line. The computer keeps running commands until it reaches the end of the program. [CENTER] [B]2.3 Expressions[/B] [/CENTER] Here is another program: print "2 + 2 is", 2+2 print "3 * 4 is", 3 * 4 print 100 - 1, " = 100 - 1" print "(33 + 2) / 5 + 11.5 = ",(33 + 2) / 5 + 11.5 And here is the output when the program is run: 2 + 2 is 4 3 * 4 is 12 99 = 100 - 1 (33 + 2) / 5 + 11.5 = 18.5 As you can see Python can turn your 50 thousand RS computer into a 150 RS calculator. Python has six basic operations: Operation Symbol Example Exponentiation ** 5 ** 2 == 25 Multiplication * 2 * 3 == 6 Division / 14 / 3 == 4 Remainder % 14 % 3 == 2 Addition + 1 + 2 == 3 Subtraction - 4 - 3 == 1 Notice that division follows the rule, if there are no decimals to start with, there will be no decimals to end with. (Note: This will be changing in Python 2.3) The following program shows this: 4 Chapter 2. Hello, World print "14 / 3 = ",14 / 3 print "14 % 3 = ",14 % 3 print print "14.0 / 3.0 =",14.0 / 3.0 print "14.0 % 3.0 =",14 % 3.0 print print "14.0 / 3 =",14.0 / 3 print "14.0 % 3 =",14.0 % 3 print print "14 / 3.0 =",14 / 3.0 print "14 % 3.0 =",14 % 3.0 print With the output: 14 / 3 = 4 14 % 3 = 2 14.0 / 3.0 = 4.66666666667 14.0 % 3.0 = 2.0 14.0 / 3 = 4.66666666667 14.0 % 3 = 2.0 14 / 3.0 = 4.66666666667 14 % 3.0 = 2.0 Notice how Python gives different answers for some problems depending on whether or not there decimal values are used. The order of operations is the same as in math: 1. parentheses () 2. exponents ** 3. multiplication *, division \, and remainder % 4. addition + and subtraction - [CENTER] [B]2.4 Talking to humans (and other intelligent beings)[/B] [/CENTER] Often in programming you are doing something complicated and may not in the future remember what you did. When this happens the program should probably be commented. A comment is a note to you and other programmers explaining what is happening. For example: #Not quite PI, but an incredible simulation print 22.0/7.0 Notice that the comment starts with a #. Comments are used to communicate with others who read the program and your future self to make clear what is complicated. [/QUOTE]
Insert quotes…
Verification
Nawa warak dahaya keeyada? (Namaya wadi kireema dahaya)
Post reply
Top
Bottom