PyGame Lesson 1 Learner resource.pdf
Document Details
Uploaded by CapableTsavorite
Curro Rivonia
Tags
Full Transcript
Python Game Coding Level 1 | Learner resource | Lesson 1 Introduction to the print function What is Python? Python coding refers to the process of writing instructions in the Python programming language to creat...
Python Game Coding Level 1 | Learner resource | Lesson 1 Introduction to the print function What is Python? Python coding refers to the process of writing instructions in the Python programming language to create software, automate tasks, and solve problems. Python is a versatile and powerful language that can be used for a wide range of applications. With Python, you can develop: Web applications. Build mobile apps. Analyse data. Create games. Perform scientific calculations. Develop artificial intelligence models and much more. It provides a vast array of libraries and frameworks that make it easier to accomplish these tasks. Python is simple and readable, and large community support makes it an ideal language for beginners and experienced developers. Access Python and IDLE Follow the prompts on the Inspire Campus. STEP 1: Download Python STEP 2: Start IDLE STEP 3: Open the Command Prompt and ensure you type the following exactly: 1 Python Game Coding Level 1 | Learner resource | Lesson 1 IDLE Windows – the Shell and the Editor window IDLE stands for "Integrated Development and Learning Environment." It is an integrated development environment (IDE) that comes bundled with Python. IDLE provides a user-friendly interface for writing, running, and debugging Python code. It is often considered as a beginner-friendly IDE, as it offers a simple and intuitive environment for learning and experimenting with Python programming. IDLE has two windows in which you can code, see the image below for the difference. When coding in the Shell window – you cannot save or edit your codes once you press ENTER. The Shell will also run an output instantly. In the Editor Window, you can save codes, and go back and edit them. You need to save your code before running it. 2 Python Game Coding Level 1 | Learner resource | Lesson 1 Code colours In most programs, different parts of the code will have different colours, or none. IDLE automatically colours the text to highlight the different parts of the code. Debugging your code If you run a code and nothing happens, or if you get a whole lot of red writing or highlights, it means there is an error in your code, and you need to debug your code. 3 Python Game Coding Level 1 | Learner resource | Lesson 1 Complete all the activities on the Inspire Campus by following the prompts. Try each code that is demonstrated. Print function The print() function in Python is used to display or output information to the console or terminal. It takes one or more values as arguments and prints them as text, allowing you to see the output of your program or display messages to the user. Write a print function in words: print(“Your message”) Your message 4 Python Game Coding Level 1 | Learner resource | Lesson 1 Arithmetic operators Python can also work as a calculator – see the arithmetic operators below. How to write sums: Use no inverted commas, only brackets. print(2+2) print(2-1) print(2/2) print(2*2) print(2**2) 5 Python Game Coding Level 1 | Learner resource | Lesson 1 Strings In Python, a string is a sequence of characters enclosed within single quotes ('') or double quotes (""). Strings can be separated by commas. print(“My name is John” , “I can code”) My name is John I can code Later we will learn to add variables to strings. Print Function Purpose Code Print function Prints out the words you add in print("Hello, World!") Words (brackets) and “inverted Hello World commas” Print function Use brackets after print. Use print(2+2) Mathematics no inverted commas for sums. 4 Print and Use (brackets) after print. print(“My favourite number is”, separate strings Add ,commas, between your 6+10) strings. My favourite number is 16 Use “inverted commas” for words. print(“My favourite number is”, Numbers can be written as is 6+10, “which is the day of my or using operators: birthday”) + - / * ** My favourite number is 16 which is the day of my birthday 6 Python Game Coding Level 1 | Learner resource | Lesson 1 Lesson 1: Independent Activity Complete this activity in the Editor Window so that you can save it. Open a New Folder in IDLE and save this code as Python Game Coding Lesson 1. Create a code that responds as follows. Hi, welcome to my first Python Code. I have learnt how to use the print function and how to use Python as a calculator. My favourite numbers are, 12 times 9, and , 6 divided by two. Maths is easy I’m really great at using Mathematical operators. Here are the answers to some sums. 6*2 9+3 16-8 84/2 12 to the power of 2 7