During session 4
Exercises
NB! The practical session exercises are provided in such capacity that more experienced students would also find them interesting. It is not expected of you to get all of them done during one session. However, you are always welcome to complete the unfinished tasks at home!
1. Bar chart
Create a text file that contains 10 integers (each number on a separate line). Write a program that reads the numbers from the file and draws a bar chart based on the numbers (use tkinter and the canvas). The columns whose values are equal or greater than 50 should be in red; otherwise, the columns should be in blue. The values have to be added under the columns.
Example of the result:
2. Strong password detection
Write a function that uses regular expressions to make sure a password is strong. A strong password consists of at least eight characters, contains letters in both uppercase and lowercase, and at least one digit. You may need to test the password against multiple regular expressions to validate its strength.
3. Exam example exercises
Proceed with some examples of the exam test and the programming exercises:
4. Colors
You can find a list of color names that the tkinter module recognizes from http://wiki.tcl.tk/16166. Multiword color names are placed in curly brackets - you can ignore them. Write a program that displays as many of these colors as possibles. Use tkinter to solve the task.
An example of the output (easier):
An example of the output (harder):
If
- x and y are coordinates of the starting point,
- r is the radius,
- a is the angle of rotation (2*PI/number_of_colors),
- i is the iteration variable (from 0 to the number of colors),
then the coordinates of the second point (at the end of the line) are
- x+r*sin(i*a)
- y+r*cos(i*a)