Filters

Other

D

Your name is required for this document. It is only stored on this local computer and no where else. Please enter your name below:

S3 ComputingIf Statements Worksheet

Knox badge
S3 ComputingIf Statements Worksheet

We know that for an if statement to be followed we need the condition to be true. If we had two variables, A and B and one of those was true and our condition was A or B then we would get true. If the condition was changed to be A and B, then the result of the condition would be false.

Can the pupil leave?

The following table gives a condition to the pupil given by the class teacher. Complete the table showing whether the pupils get to leave the classroom based on the teacherโ€™s conditions.

Teacher says before pupils can leave they must Pupils do Can pupils leave?
"Put all chairs under desks and all notes in bag" Pupils put all chairs under desk Yes
Yes
"Complete task 1 or attempt programming worksheet" Half the class do task 1 and finish it and the other half start programming worksheet Yes
Yes
"Score 50 marks in an online test or pass your class test" All pupils passed the class test but only half managed to get 50 marks the online test Yes
Yes

Truth Tables

  • 1

    Complete the following table

    A B A and B A or B
    True True True True
    True False False True
    True
    False True True
    True
    True
    False False True
    True
    True
    True

    Test your answers by writing a program to do that.

  • 2

    Complete the following table

    Variable 1 Variable 2 Condition Result
    A = 10 B = 50 A < B True
    True
    A = 50 B = 20 B < 50 True
    True
    C = 31 A = 31 C == A True
    True
    A = 30 B = 25 A == B or B > 30 True
    True
    A = False B = True A and B True
    True
    A = False B = True A or B True
    True

    Test your answers by writing a program to do that.

Python challenges

  • 1

    Write a multiple-choice quiz program that makes use of if statements. The quiz can be on any topic you like related to school, for instance you could do a quiz on physics or history. This program will ask the user to type a number 1, 2, 3 or 4 to give the answer and will look something like the following:

    The steps for the program are as follows:

    1. Set a total points variable to 0 (total_points = 0)
    2. Display the question (print("What is the capital of Germany?"))
    3. Display the options (print("1 = Paris, 2 = Berlin, 3 = Sofia, 4 = Madrid"))
    4. Ask the user for their answer and store it in a variable called user_answer (user_answer = input()). Note that the code solution here is not complete, something is missing!
    5. Now check that the number of the answer matches the number given by the user. (if user_answer == 2:).
    6. Finally, if they give the correct answer, give them one point. If they give the wrong answer, donโ€™t give them a point. (total_points = total_points + 1)
    7. Now move onto the next question and repeat from step 2 onwards.
    8. When you have programmed all of the questions, display the number of points. (print(total_points))

    Add your code below:

  • 2

    Write a Python program that takes a student's score as input and classifies it into a letter grade based on the following scale:

    • A : 70%+
    • B : 60%+
    • C : 50%+
    • D : 40%+

    Steps:

    1. Use an input statement to get the student's score.
    2. Use if statements to determine the letter grade.
    3. Print the corresponding letter grade.
  • 3

    Write a Python program that functions as a simple calculator. The program should:

    1. Ask the user to input two numbers.
    2. Ask the user to choose an operation (addition, subtraction, multiplication, division).
    3. Perform the chosen operation and display the result.
Provide Feedback

What did you think of this document?

!
-- DragonDocs version 0.9 --

20.08.2017

Started on DragonDocs
Created a YASS/PHP and HTML-based system for saving and retrieving data

21.08.2017
Added CSS styles to page
Added JavaScript code to the page

02.02.2018
Added the multipage option (used in my dissertation)
Added the XMLHttpRequest-based multipage requests

08.02.2018
Added the Accessibility features
Filters added

10.02.2018
Purple filter added

17.03.2018
Added the Note class
Added the Did You Know class

-- DragonDocs version 1.0 (Yosemite) --

02.10.2019
First trial of DragonDocs in teaching

04.10.2019
Added the Task, Starter, Review your learning sections

07.10.2019
Added the feedback feature
Added the Dark Mode toggle

19.09.2020
Performance gains through the removal of unnecessary code
Added the Learning Intentions and Success Criteria features
Added the school badge

31.09.2021
Changed the headings (h2) to be more consistent with my website
Added sections to the pages - sections must be preceded by a h2
Added the "I have read this section" buttons
Changed the main heading zone to gradient text like my website
Added the table of contents feature

02.02.2022
Added the Print feature
Updated the footer to feature a new gradient
Added the Test It! class
Added the green flag
Automated the table of contents using JavaScript

06.02.2022
Added the 'includes' feature to the document, allowing inclusion of other files easily
Removed the requirement that the IP address must be one of the schools I have taught at, opening these documents to the public

02.03.2022
Once a section has been read or completed, the user can now hide that section

10.10.2022
Added the Extension task class
Changed the scrollbar on Windows to match that of macOS

-- DragonDocs version 2.0 (Kilimanjaro) --

07.08.2023
Added the Save button and the ability to save 'results' or answers to a Word document

12.01.2024
Added the large numbers class
Removed the background of the page navigation

-- DragonDocs version 2.1 (Aurora) --

08.02.2024
Added the active class to active links in the bottom section

09.02.2024
Added the image upload feature

10.02.2024
Added a fix that prevents the upload of non-image files into an image upload
Added pasting images to the upload feature

11.02.2024
Added the ability to view the changelog from a document
Improved the feedback system by recording the DragonDocs User ID and the Document ID data
The feedback from DragonDocs can be accessed much easier

12.02.2024
Added the new step_by_step_mode feature, allowing sections to be viewed individually
Added the ability to lock and unlock DragonDocs

22.02.2024
Added new checkboxes to each list item in a .task or .step
Added functionality to said checkboxes to add a strikeout to steps completed

23.02.2024
Added the new 'step' class
Steps are now auto incremented in CSS so the name displays the step number
Activities are now also auto incremented to display the activity number

25.02.2024
Added the 'matcher' feature to DragonDocs
Fixed an issue in which a closed section would retain it's original height within the document navigation
Added starters and the lesson review to the navigation on the side
The learning intentions and success criteria in teaching documents have now been redesigned to match my slides design

26.02.2024
All buttons are now on the right hand side
The accessibility button now has WAI under it

-- DragonDocs version 2.2 (Serengeti) --

26.02.2024
Code has been rewritten from the ground up to be object-oriented, making additional features easier to add

28.08.2024
Changed the look of grouped multiple choice buttons

06.03.2024
Added the new dragondocs_name feature and the requires_name property which allows names to be prepended to saved documents

09.03.2024
Added code so when the user types in their name and hits the enter key it will save that data and close the modal window
Added the new DragonShow and DragonDocs Link - a connection between both services that allows the presenter to communicate with users of DragonDocs from a DragonShow
Added the new timer option which is sent from DragonShows

04.04.2024
The matcher feature is no longer embed from jamiebalfour.scot but actually a feature of DragonDocs
Made DragonDocs 100% object-oriented, meaning much better management and better performance

05.04.2024
Made subtle changes to the interface to tidy it up a bit

06.04.2024
The multiple choice questions are now also part of the object oriented interface

09.04.2024
As requested, h3 elements are now included in the 'floating navigation'
The active navigation element now becomes bold and the left border has been retired

05.06.2024
Saving files now exports as a PDF which now also embeds all fonts (removed now)

18.06.2024
Select dropdowns are now temporarily saved to local storage and are now recovered when the document is reopened

19.12.2024
Multipage navigation now switches pages seamlessly - it's beautiful

17.01.2025
Added support for multi-select storage and reloading

-- DragonDocs version 2.3 (Great Barrier) --

17.02.2025
Added support for reorder tasks
Added lines and attachment circles for matching tasks

19.02.2025
Improved the performance of API calls
Separated the API from the core HTTP code

20.02.2025
Colours can be applied to matcher elements
Matcher colours now match the colours of the elements

Time left

: