Presentation is loading. Please wait.

Presentation is loading. Please wait.

Beginning Python Programming

Similar presentations


Presentation on theme: "Beginning Python Programming"— Presentation transcript:

1 Beginning Python Programming

2 Getting Started IDLE is Python’s Integrated Development Environment (IDE) and interpreter IDLE looks like a text editor but understands Python Run IDLE and look at the Shell (Python’s interpreter) Python version Prompt The print() command means ‘show on the screen’ not ‘send to the printer’ At the prompt, type in: print(“Hello World”) and press <Enter> 2 of 12

3 Don’t panic! These messages are trying to help you!
Did it work?! IDLE allows you type a single line of code and run it You should see this: You might have an error like this: Don’t panic! These messages are trying to help you! Beginning Python 3 of 12

4 Syntax Errors Syntax errors are mistakes in your use of a programming language; rather like saying “I are going to the shops” in English… A string literal is something in quotes… Try all these… 4 of 12

5 I’m sure you can come up with some better jokes than these!
Challenge 1 Write some to code to tell your favourite (polite) joke… Hint: You need to type two separate print() commands Q: What washes up on tiny beaches? A: Microwaves Q: What goes clip? A: A one-legged horse Q: Why shouldn’t you write with a broken pencil? A: Because it’s pointless! Q: How do you make a fire with two sticks? A: Make sure of them is a match! I’m sure you can come up with some better jokes than these! 5 of 12

6 Try out all of the escape sequences…
Can we do this with one line of code? How can we put a blank line in a string? We can’t type it in… We can use an escape sequence Escape Sequence Effect \n Creates a new line \t Inserts a tab indent \\ Allows a backslash to appear in a string of text \” Allows a speech mark to be used in a string of text Try out all of the escape sequences… Beginning Python 6 of 12

7 Mathematical Operators
You can use the Python interpreter as a calculator Operator Name Example Answer + add 17+3 20 - subtract 20-11 9 * multiply 15*3 45 / divide (normal) 11/5 2.2 // integer divide (the whole number part only) 11//5 2 % modulus (remainder of a division) 11%5 1 ** exponent (to the power of…) 10**2 100 Try these out… Beginning Python 7 of 12

8 What is print( )? print() is a built-in function; a small program included in Python to perform a particular task print() expects a value within the brackets. This is called an argument or parameter, it is passed to the print() function. print() displays the passed value on the screen Someone wrote the print() function… You will learn to write your own functions later on. Beginning Python 8 of 12

9 Putting it together You can pass multiple things to the print function
Commas are used to separate different parts of the things we want to be displayed The print function inserts a space between each part Things in quotes are printed as they are, things with no quotes are evaluated and the result printed… Beginning Python 9 of 12

10 Exercises Display "15 cubed is", followed by the answer
Display the following using one line of code: Welcome to my program I’d just like to say "hello!" Fix the following Python statement: Print("Good afternoon") Fix the following Python statement: print("17 / 5 =" 17/5) Beginning Python 10 of 12

11 Exercise Solutions . You need to use a escape sequences here (\n and \”) Python is case sensitive, it is print(), not Print() You must separate all parts of a print statement with commas Beginning Python 11 of 12

12 Summary We have looked at:
IDLE and used the Shell (Python’s interpreter) The print() function Escape sequences Mathematical operators Combining strings and maths Beginning Python 12 of 12


Download ppt "Beginning Python Programming"

Similar presentations


Ads by Google