Page 57 - Touhpad Ai
P. 57

u  Follow the snake_case convention for variable names and function names. This means using all lowercase letters with
                   words separated by underscores. For example: my_variable, calculate_sum.
                 u  Follow  the PascalCase convention for class names. This means capitalising the first letter of each word, without
                   underscores. For example: MyClass, BankAccount.
                 u Use all uppercase letters with underscores to denote constants. For example: MAX_SIZE, PI.

                 Literals
                 Literals in Python represent fixed values that are used directly in the code. They can be of several types:
                 u Numeric literals: Represented as integers, floating-point numbers, or complex numbers. Examples: 42, 3.14, 1 + 2j.
                 u  String literals: Represented as sequences of characters enclosed in single, double, or triple quotes. Examples: 'hello',
                   "world", '''multiline string'''.
                 u Boolean literals: Represented as True or False.
                 u None literal: Represented as None that indicates the absence of a value.

                 Operators

                 In Python, operators can be defined as special symbols which perform arithmetic and logical computation. The values
                 which the operators use to get the output are called operands.

                 Arithmetic Operators

                 Arithmetic operators are used to perform mathematical operations such as addition, subtraction, multiplication, division,
                 modulus, exponentiation, and floor division.

                         Operator                                    Description
                             +      Adds two operands or unary plus

                             -      Subtracts right operand from left operand or unary minus
                             *      Multiplies two operands
                             /      Divides left operand by right operand
                             %      Returns the remainder of the division

                             //     Performs floor division (a division that results in whole number adjusted to the left in the
                                    number line)
                            **      Performs exponentiation (left operand raised to the power of right operand)

                    Program 5: To demonstrate the use of arithmetic operators

                   #The input() function returns a string
                   #So we use the int() function to convert the strings to integers

                   num1 = int(input("Enter first number: "))
                   num2 = int(input("Enter second number: "))
                   # Perform arithmetic operations
                   addition = num1 + num2

                   subtraction = num1 - num2
                   multiplication = num1 * num2
                   division = num1 / num2
                   modulus = num1 % num2
                   exponentiation = num1 ** num2

                                                                                 Basic Concepts of Artificial Intelligence  55
   52   53   54   55   56   57   58   59   60   61   62