🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Blooket 02_1 Introduction to Python - variables.pptx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Transcript

Introduction to Python Programming Part 2: Using Variables Learning Objectives Rookie To assign data to a variable. To be able to output a variable as part of a outputted statement. Skill Contents Once you complete a skill, colour code the box to show your level of confidence. You can always revisit...

Introduction to Python Programming Part 2: Using Variables Learning Objectives Rookie To assign data to a variable. To be able to output a variable as part of a outputted statement. Skill Contents Once you complete a skill, colour code the box to show your level of confidence. You can always revisit the skill later on to boost your confidence. Key I am very good at this skill and could show a friend how to do it. I am confident I can perform this skill on my own. I need to improve my understanding of this skill. Colour Code Contents Naming variables Assigning data to a variable Combining variables Combining variables and string with print statements Confiden ce Level What are Variables? In programming, a variable can be described as a named storage location for data. For example, the variable A could hold the value 6, David, Elephant, a calculation, another variable (or more!), or… pretty much anything you want! As such, using variables requires a similar understanding to creating algebra expressions. An important part of creating variables is to use memorable names so we can remember what information they hold and retrieve it later on. Variable Rules A variable name cannot start with a number A variable name must not contain any spaces Task 1: Name the Variables Within the table below, think of suitable variable names to store the following information: Information to be stored The value of a dice roll The number of points collected in a computer game A computer game player’s name The date of birth of a programme user A quiz answer Suitable variable name Variable Rules A variable name cannot start with a number A variable name must not contain any spaces Skill 1: Assigning data to a variable and printing it Once data has been assigned to a variable, it can then be printed You write it like this: Allocate string to a variable Print the variable Allocating an integer to a variable Print the variable Notes When adding string, always use quotation marks. Note : that you don’t use quotation marks for printing a variable. Task 2: Rookie 1. Create a variable called a. 2. Store the phrase Hello World within it. 3. Print a. Flowchart Pseudo code START a = Hello World OUTPUT: a END Python Task 3: Rookie 1. Create a variable called points. 2. Store the integer 256 in it. 3. Print points. Flowchart Pseudo code START points = 256 OUTPUT: points END Python Skill 2: Combining variables and string in print statements Variables can be combined with string statements. This is very useful when it comes to printing out information. The + Symbol Using the + symbol as shown below allows you to join together (concatenate) data and information. Allocate data to a variable Print the variable within a sentence Output Notes In the example, notice how spaces have been created within the text so that the variable is made to look part of it. Task 4: Rookie 1. Create a variable and store the name of your favourite sports team. 2. Print it within the following statement: “[variable] is the greatest sports team in the world!” Flowchart Pseudo code START variable = sports team OUTPUT: variable + is the greatest sports team in the world! END Python Task 5: Pro str( ) function You can convert integer numbers stored within a variable into string name in it.using this command. Alternatively add the integer with a age in it. comer. 1. Create a variable and store your 2. Create a variable and store your 3. Print it within the following statement: “Hello[name], you are [age] years old” Flowchart Pseudo code START name = user INPUT( ) age = user INPUT( ) OUTPUT: Hello + name + , you are + age + years old END Python Or

Use Quizgecko on...
Browser
Browser