Week 3


Week - 3 

We started making our own blogs in which we post our weekly progress, we were also given activities to complete to help us understand python better

Activity - 1 - Making decisions 

- Declares an integer variable and sets its initial value to 0;

- Asks the user to enter a number, then stores the entered number in your variable; and finally

- Tells the user what their number was.

We now want to modify this Python script, so that whenever the number entered by the user is lower than 12, the message “lower than 12” is also printed to the console. To do this you should use an if-statement in Python to implement decision-making. You can read more about decision-making here.

Test your script several times with numbers that are lower, higher and equal to 12 to see that the script is working as intended. Make sure that you fully understand how the script works.

Activity - 2 - More Decisions

Now modify the script from the previous step so as to perform as follows:

a) If the number entered by the user is lower than 7, the message “lower than 7” is printed to the console;

b) Otherwise, if the number is 7, “It is 7” is printed; and

c) Otherwise, the message “more than 7” is printed.

Activity - 3 - Python Conditionals

 

a) declare a variable called y, which is initialised to a value between 1 and 100 (you can choose this value), then

b) write and test short scripts to do each of the checks below. Make sure that your scripts look professional, e.g. include full comments within them explaining their functionality (Note: full commenting of your scripts will be expected for all the artefacts you submit with your TOFA portfolio).

- If y is equal to 1, print out “y is 1”

- If y is greater than 5, print out “y is high”

- If y is less than 5, print out “y is low”

- If y is not 7, print out “y is unlucky”

- If y is either 2 or 3, print out “y is 2 or 3”

- If y is more than 4 but “less than or equal to” 7, print out “y is mid-range”

Activity - 4 - Short Circuit

Leave a comment

Log in with itch.io to leave a comment.