Category: Uncategorized

24. Other string things

There are other useful functions for checking and manipulating characters and strings Reversing a string Sometimes you might need to reverse a string. This may be to make a working with binary strings easier, or to help create random passwords. Tasks Type in the code and make sure that it works Add code to reverse […]

22. Checking Strings

We can check strings using the same methods as with numbers A character is simply a string with a length of 1 The in operator is a quick way of checking if one string or character is contained within another – useful to check user input against an allowed list of characters or symbols Some […]

21. Test 3 – Calculator

Main Task Create a basic calculator program that will take two numbers, and perform one of the following functions depending on what the user chooses: add subtract multiply divide You should assume that all user input will be valid whole numbers. You should ask the user which function they wish to perform. The output should […]

20. Logical Operators

Logical operators allow you to combine checks on variables The two operators are OR and AND OR will be true if either condition is met AND will be true when both conditions are met In Python, they are always written in lowercase Tasks Type in the code and test that it works Modify the program […]

19. Checking Data Types

It is very important to be able to check the type of data entered If you try to convert data to a type that won’t ‘fit’, your program will crash The code below will crash if a non-numeric input is supplied The example below uses the Try/Except statement to catch the error The program attempts […]