Python VII

Mary PW Chin 钱碧慧博士
PhD (Wales), MSc (Surrey)
E-mail:

1st bite of Python

Printing

2nd bite of Python

Loops

3rd bite of Python

If-elif-else

4th bite of Python

Nested loops

5th bite of Python

Input, while, tables

6th bite of Python

Strings

7th bite of Python

Simple maths

8th bite of Python

More loops

9th bite of Python

Dictionaries

10th bite of Python

Drawing

11th bite of Python

Statistics & histograms

12th bite of Python

Pretty nets

13th bite of Python

Medical scans

14th bite of Python

Handwriting recognition

15th bite of Python

Flower recognition

Algorithm design using simple maths

Slides here are continuously being revised and updated. If you have been here before, your browser might have some old files cached. To ensure that you see the latest version, please follow the instructions given in the following link: ☞ how to clear browser cache.

Gentle reminder

For every program you encounter it is always an excellent exercise to change the variable names to names which are most meaningful to you, then make the program run. You will gain deeper understanding of the program. You will see the program in a new light. Everyone is different: variable names most intuitive to me differ from variable names most intuitive to you. My programs are written with variable names most intuitive to me, so you should change them to names most intuitive to you so that the program flow becomes more obvious.

Synopsis
  1. Nested loops;
  2. while loops;
  3. functions and returns;
  4. more drills on logic;
  5. multiplying using the + operator only, without the * operator;
  6. raising to power using the * operator only, without the ** operator or the pow function;
  7. finding the minimum, maximum and average of a list of numbers manually, without using built-in function;
  8. converting between decimal, binary, octal and hexadecinal number systems with and without using built-in functions int, bin, oct and hex.
  9. formatted printing.

Exercise
  1. Write a program that prints the multiplication tables for 2, 3, 4, 5, 6, 7, 8 and 9:
    122
    224
    326
    12224
    133
    236
    339
    12336
    14 4
    24 8
    34 12
    124 48
    15 5
    25 10
    35 15
    125 60
    16 6
    26 12
    36 18
    126 72
    17 7
    27 14
    37 21
    127 84
    18 8
    28 16
    38 24
    128 96
    19 9
    29 18
    39 27
    129 108
  2. Write a program that prints a combined multiplication table for 2, 3, 4, 5, 6, 7, 8 and 9 as follows:
    n22*n33*n 44*n 55*n 66*n 7 7*n 8 8*n 9 9*n
    122334455667 7 8 8 9 9
    224 36 48 510 612 7 14 8 16 9 18
    326 39 412 515 618 7 21 8 24 9 27
    2 3 4 5 6 7 8 9
    2 3 4 5 6 7 8 9
    12224 336 448 560 672 7 84 8 96 9 108
  3. Write a program that prints the following with as few repetitions as you can:
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              
  4. Write a program that prints the following with as few repetitions as you can:
               *..*..*..*..*
                *..*..*..*..*
                 *..*..*..*..*
               *..*..*..*..*
                *..*..*..*..*
                 *..*..*..*..*
               *..*..*..*..*
                *..*..*..*..*
                 *..*..*..*..*
              
  5. Write a program to generate a random number 1930 ≤ y ≤ 2017, take this as somebody's year of birth. Generate another random number 1 ≤ m ≤ 12, let this be his month of birth. We need to know his age in the coming years until he reaches 90. Print your output in three columns:
    YEARMONTHAGE
    20181__ years __ months
    20182
    20183
    ____90 years 0 month

Challenge

Pixar Animation

1st bite of Python

Printing

2nd bite of Python

Loops

3rd bite of Python

If-elif-else

4th bite of Python

Nested loops

5th bite of Python

Input, while, tables

6th bite of Python

Strings

7th bite of Python

Simple maths

8th bite of Python

More loops

9th bite of Python

Dictionaries

10th bite of Python

Drawing

11th bite of Python

Statistics & histograms

12th bite of Python

Pretty nets

13th bite of Python

Medical scans

14th bite of Python

Handwriting recognition

15th bite of Python

Flower recognition