Presentation is loading. Please wait.

Presentation is loading. Please wait.

Input, Output and Variables GCSE Computer Science – Python.

Similar presentations


Presentation on theme: "Input, Output and Variables GCSE Computer Science – Python."— Presentation transcript:

1 Input, Output and Variables GCSE Computer Science – Python

2 Input To get input from a user: x = input(“What is your name?”) y = int(input(“Enter a number”))

3 Output To show output to a user: print (“hello”) print (67) print (x) If you’re printing a string, you need to include quotes. If you are printing a number or the contents of a variable, these are not needed.

4 Variables Variables in Python: Integer - No decimal places – 78 Float - Decimal places - 45.767 String - Text Boolean - True or False

5 Variables Variables are assigned a value using the = sign. x = “hello” pizza = 78 doobedoobedo = True

6 Converting Variable Types You want to convert a variable to a different type: str() int()

7 Maths With integer and float variables, you can do maths! addition = 67 + 5 multiplication = 98 * 2 answer = multiplication + 4 print (answer)

8 Joining Strings (Concatenation) You can join (concatenate) strings (text) together using +: y = “hello ” x = “Joshua” print (y + x)

9 Joining Strings and Integers You can join (concatenate) a string (text) and integers (numbers) together. You will need to convert the integer into a string: y = “Your score was: ” x = 10 print (y + str(x))

10 Individual Tasks For each of the following tasks: Use Python (IDLE) to code the solution. Copy and paste your solution into this PowerPoint Presentation. You can add additional slides!

11 1. Allow the user to input two numbers, printing out the sum of the numbers.

12 2. Allow the user to input three numbers, printing out the sum of the first two numbers, multiplied by the third number.

13 3. Ask the user for their name. Say Hello. For example: If the user enters “Joshua”, print out “Hello Joshua”

14 4. Extend Task Three. After “Hello Joshua”, ask the user “How are you?”

15 5. Ask the user to enter a number between 1 and 100. Print out “Your score is: ” and their number.

16 6. Extend Task Five. Print out “Your Score is: “ double (x2) their number.

17 7. Ask the user for their name, their age and where they live. Print out their name, age and where they live using full sentences! For example: If the user enters “Derby”, print out “You live in Derby”


Download ppt "Input, Output and Variables GCSE Computer Science – Python."

Similar presentations


Ads by Google