Presentation is loading. Please wait.

Presentation is loading. Please wait.

GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python.

Similar presentations


Presentation on theme: "GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python."— Presentation transcript:

1 GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python

2 GCSE Computing: Programming www.computerscienceuk.com Activity 1 What do you see? What do you think is happening? What do you imagine could happen with this program? 3 mins

3 GCSE Computing: Programming www.computerscienceuk.com Remembering how to program in Python How do we output text onto the screen? print (“Hello World”) Demonstration Time! Learning Objectives: Remember the following Programming Skills: - Outputting text to the screen -Storing inputted data into a variable -Working with numbers -Making Decisions (IF-ELSE)

4 GCSE Computing: Programming www.computerscienceuk.com Remembering how to program in Python On your whiteboards write the code to display a message of your choice. Lets mark each others… print command word? Brackets used? Speech marks around text? Learning Objectives: Remember the following Programming Skills: - Outputting text to the screen -Storing inputted data into a variable -Working with numbers -Making Decisions (IF-ELSE)

5 GCSE Computing: Programming www.computerscienceuk.com Remembering how to program in Python Learning Objectives: Remember the following Programming Skills: -Outputting text to the screen - Storing inputted data into a variable -Working with numbers -Making Decisions (IF-ELSE) How do we ask the user for an input and store what they type in? variable = input (“What is your name?”) Demonstration Time!

6 GCSE Computing: Programming www.computerscienceuk.com Remembering how to program in Python Learning Objectives: Remember the following Programming Skills: -Outputting text to the screen - Storing inputted data into a variable -Working with numbers -Making Decisions (IF-ELSE) On your whiteboards write the code which displays the question “what is your age?” and stores the number that is to be entered in a variable called “age”. Lets mark each others… age = variable assignment? input(“what is your age?”) command?

7 GCSE Computing: Programming www.computerscienceuk.com Remembering how to program in Python Learning Objectives: Remember the following Programming Skills: -Outputting text to the screen - Storing inputted data into a variable -Working with numbers -Making Decisions (IF-ELSE) Data Types and Arithmetic What different types of data are there? String This means any keyboard character (letters, numbers symbols) Integer This means any whole number. If the computer knows the data is an integer it can do maths with the data Real This means any decimal (fractional) number

8 GCSE Computing: Programming www.computerscienceuk.com The need to tell the computer what data type the variable will store Computers store values in variables In order for the computer to understand our inputs, it needs to know what type of data our input is. If a variable is to hold a word, we must tell the computer that the variable is to contain a string. If a variable is to hold a whole number, we must tell the computer that the variable is to contain an integer – so it can do calculations. If we don’t do this the program will not work. Variable Mr Wickins 30 CSUK

9 GCSE Computing: Programming www.computerscienceuk.com Doing Arithmetic If we want our program to work with numbers we must tell the program that certain variables will hold numbers. When we input a number into our program var1 = input(“please enter a number”) python automatically sets the variable as a string (a word, for example twenty instead of 20 ) If we want to do maths with the ‘inputs’ we need to tell the computer that it’s a number (integer)

10 GCSE Computing: Programming www.computerscienceuk.com Converting Data Types To do this we need to convert the variable to an ‘integer’ or ‘real’ data type. Above you can see that two numbers have been entered and stored in variables num1 and num2. As python stores inputs as strings we need to convert these variables into integers.

11 GCSE Computing: Programming www.computerscienceuk.com What’s going on? Variable 29 Variable Twenty Nine 29 Mr Int. Num1 Twenty Nine I’m telling the computer that this variable contains a number not a word!

12 GCSE Computing: Programming www.computerscienceuk.com Once they have been converted we’re ready to do maths! Num1 Five Num2 Nine Num1 Five Num2 Nine 5 9 59 + Answer 14 Answer 14

13 GCSE Computing: Programming www.computerscienceuk.com Remembering how to program in Python Learning Objectives: Remember the following Programming Skills: -Outputting text to the screen - Storing inputted data into a variable -Working with numbers -Making Decisions (IF-ELSE) On your whiteboards write the code which will ask the user for 2 numbers, convert them to integers and then multiply them together before displaying the result. Lets mark each others… number[x] = input(“Enter a number”) X2? number[x] = int(“number[x]”) X2? answer = number1 * number 2 print(answer)

14 GCSE Computing: Programming www.computerscienceuk.com Tasks Write a program that: 1)Displays a message of your choice to the screen 2)Asks the user for their favourite colour and then comments on the colour entered (for example, “**colour entered**, is a nice colour!” 3)Asks the user for their age and then displays what their age will be in 50 years. 4)Asks the user for the dimensions for a box and then works out its volume 5)Asks the user for their weekly pocket money, weekly phone bill, money spent on food each week and money spent on seeing friends each week. The program is to then display how much pocket money will be left when the week is over. #comment on your code!

15 GCSE Computing: Programming www.computerscienceuk.com Commenting # Starting a line with a hash will turn your text into a comment. (It will be ignored by the program)

16 GCSE Computing: Programming www.computerscienceuk.com Extension Read up on IF-ELSE statements Watch the video on the website Begin trying to solve / program the extension task (next slide)

17 GCSE Computing: Programming www.computerscienceuk.com Extension and Next Week’s Task Guessing game Description The computer will pick a number between 1 and 100. (You can choose any high number you want.) The purpose of the game is to guess the number the computer picked in as few guesses as possible. Input The user will enter his or her guess until the correct number is guessed. Output The program will keep asking the user to guess until he or she gets the number correct. Then the program will print how many guesses were required. Sample session Time to play a guessing game. Enter a number between 1 and 100: 62 Too high. Try again: 32 Too low. Try again: 51 Too low. Try again: 56 Congratulations! You got it in 4 guesses.


Download ppt "GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python."

Similar presentations


Ads by Google