Page 163 - CodePilot V5.0 C8
P. 163

The output of the preceding code would be as follows:

                     Output

                  Welcome to the Random Math Quiz!
                  Type 'q' anytime to quit.
                  Question 1 : 8 + 5 =?
                  Enter your answer (or 'q' to quit): 13
                  Question 2 : 7 – 9 =?
                  Enter your answer (or 'q' to quit): –2
                  Question 3 : 7 * 5 =?
                  Enter your answer (or 'q' to quit): 35
                  Question 4 : 1 * 10 =?
                  Enter your answer (or 'q' to quit): 10
                  Question 5 : 9 * 10 =?
                  Enter your answer (or 'q' to quit): 90
                  Your final score is: 5





                 TECH
                   T       ¢   Index: A unique serial number allocated to each element of the string starting with 0.
                   E
                   R       ¢   Replication: Repeating the string a specified number of times.
                   M
                   S           Traversing: Going through each item in a string or list one by one to access or process it.
                           ¢





                 REWIND RUN



                 «   A function can be defined as a block of reusable code that performs a specific task.
                 «   A Python function consists of the following components: def keyword, function name, parameters,
                    function body, return statement and the return keyword.
                 «   A group of characters enclosed in single or double or triple quotes is called a string.

                 «   The string comparison operator (>, <, >=, <=, ==, !=) in Python is used to compare two strings.
                 «   A list in Python can be defined as an ordered collection of items that can store multiple values in a
                    single variable.

                 «   To create a list, you can place the elements inside square brackets, separated by commas.
                 «   A module  is a Python  file containing  functions,  classes  and variables  that  you  can include  in
                    your program.

                 «   The math module in Python contains functions for carrying out mathematical tasks.
                 «   The built-in random module provides functionality for generating random numbers.







                                                                                                                  161
                                                                                            Step Ahead with Python
   158   159   160   161   162   163   164   165   166   167   168