Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMPUTER PROGRAMMING PYTHON

Similar presentations


Presentation on theme: "COMPUTER PROGRAMMING PYTHON"— Presentation transcript:

1 COMPUTER PROGRAMMING PYTHON

2 Previously You saved a file that asked a user some questions, like what is your favourite food and where do you live. Can you find the file? Can you open it?

3 Add another question and response
Add another question – ask the user to name a place where they have been on holiday. The response must be; “Hmmm…. “ + holiday_location + “sounds like a nice place to go”

4 Commenting code Comments are added to computer programs to help people understand the intentions of the person who created the code – especially where it is not obvious what is going on.

5 # Now add comments to all of your lines of code
################ # Now add comments to all of your lines of code

6 Add comments to your program
Think, pair, share 1. How would you add some information about the program, creator, date etc 2. Is it necessary to comment on every line? 3. If everything is ignored after the #, how could this be useful?

7 Answers 1. Add a top line comment with name, date etc 2. Only comment when it is not clear to another person 3. You can use the # to “comment out” sections of code that are not working to help with debugging

8 Creating a maths quiz Open a new program editor window (open the interpreter and select File, New Window)

9 Here is the code: save as maths_questions

10 Add more questions to your game
Can you add more maths questions to your game questions? How many can you do? Did you do them on your own or did you need some help?

11 Can you answer this question?
Answer = int(answer) Thinking back to the use of integers in the last lesson, what does this do and what does int mean?

12 Answer = int(answer) This converts the text string into a number or integer. If it was not converted to an integer, it could not be compared to another integer, the answer 4.

13 Can you answer this question?
if answer ==4: What does the == translate to in plain English?

14 if answer ==4: This means ‘equal’ to, as in “is it equal to?”

15 Can you answer this question?
else

16 else Or else

17 Can you answer this question?
Why are the indents necessary after the if and else statements?

18 Indents This means follow the these instructions if the statement above is true.

19 Can you answer this question?
What happens if the colons are not there after the 4 or else?

20 Colons You get a syntax error

21 12 times table Create a test that will check the user’s knowledge of the 12 times multiplication table. The test should have between 4 and 12 questions. Save the file as 12_times_table It must include a header (description, your name and date) You must make use of comments (#)


Download ppt "COMPUTER PROGRAMMING PYTHON"

Similar presentations


Ads by Google