- Basic data types
- Real number
- Rules in naming variable
Note: All codes in this article are written in Python
11.1 Basic data types
A positive or negative whole number that can be used with mathematical operators.
A number with a fractional part, that can be used with mathematical operators.
Integer = int(25) // Declare an integer with the value of 25 Real = float(25) // Declare a real number with the value of 25.0
A single character.
Char = 'A' Char = "A"
A string variable has several characters in length. String vary in length and may even have no characters. The characters can be lettersand/or digits and/or any other printable symbols. For example:
exam_name = 'CIE' subject_code = '0478' entry_password = '@!&*%^$#'
A boolean variable can have only two values: TRUE or FALSE
pass_CIE_exam_with_help_of_SCIEprogrammer = TRUE
RULES IN NAMING VARIABLES
- Case-sensitive (number1 is different from Number1)
- Can contain numbers, letters and underscore
- CAN NOT start with a number
- CAN NOT be the same as Python Reserved words
E.g. max, min, sum
- USE DESCRIPTIVE NAMES and ADD COMMENTS
Otherwise, you’ll lose mark in CIE EXAM !
Statements that runs one by one in order.
first_num = int(input('Enter the first whole number:')) second_num = int(input('Enter the second whole number:')) total = first_num + second_num print('The sum equals', total)
Running the following statements depends on whether the criteria given is satisfied or not. In Python we use IF statement:
if grade == 100: print('Excellent! You got TOP IN THE WORLD in computer science.') elif grade > 80: print('Great! You can improve by spending more effort.') else: print('Oops! You need more hard work.')
Difference between single equal sign (=) and double equal signs (==)
- Single Equal Sign means to assign value or content or variable on right to the variable on the left
- It means ‘