1 / 12

Python Programming

Python Programming. Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use inputs and outputs Introduce a parameter. Isn’t there another way? - Starter.

ehill
Télécharger la présentation

Python Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python Programming Using Variables and input

  2. Objectives • We’re learning to build functions and to use inputs and outputs. Outcomes • Build a function • Use inputs and outputs • Introduce a parameter

  3. Isn’t there another way? - Starter Discuss alternative ways of doing this. This is a program which asks for a name input 5 times. print (“what is your name”) name = input() Print(name) print (“what is your name”) name = input() Print(name) print (“what is your name”) name = input() Print(name) print (“what is your name”) name = input() Print(name) print (“what is your name”) name = input() Print(name)

  4. Isn’t their another way? – Starter / Answers FUNCTIONS!! def main(): print (“what is your name”) name = input() Print(name) In terms of programming, the function is something which carries a sequence of instructions. It saves us from repeating instructions over and over.

  5. Don’t forget your input? In your previous lesson, you learnt how to store variables. We completed this program which asks for our name and age. If we want to re-use this we can put it in a function. Lets break this down….

  6. What is a function? In your previous lesson, you learnt how to store variables. The first thing you must do is define the function. This lets the program know that the function is available to use. This function creates the text hello. You should open up a new program in python and set up your code so that it uses a function. Try running it by saving it as a .py file and then press F5 on your keyboard. When in the shell, type main() to see it work.

  7. Tasks ? Write the following functions: • A function to save your name and print it to the screen. • A function to ask the user for 2 numbers and add them together • A function to ask the user for their name, age and place of birth and build a sentence with the use of the input variables.

  8. Extension – Introduction of parameters? • When creating a function within your game, you can include parameters. • They are used to customise the program. • You don’t always need the program to ask for input. You can use parameters to pass in filenames, text and other variables.

  9. Parameter – Spot the difference

  10. Parameter – Spot the difference

  11. Tasks ? Modify your functions to include parameters: • Include your name in a parameter of your first function. • Use two parameters to calculate numbers. • Use the previous example to create your own function which uses parameters for age, name and place of birth.

  12. Plenary Self Assessment: • Your teacher has issued you with a self assessment sheet. You will have today’s objects and outcomes on it. Task • Comment on the lesson. Talk about the positive experience you have had and talk about things you need a little more help on. If you managed to get onto the extension tasks, what have you found out? Include the parameters in the correct place • Your teacher has given you a piece of code. You must include the correct parameters in the correct place.

More Related