Programming 1 Term 2 Lesson
Programming 1 Term 2 Lesson
SEQUENCES.
12.6.1.1 USE THE FUNCTIONS OF THE LIBRARY RANDOM TO GET A PSEUDO-RANDOM NUMBER;
12.6.1.2 DETERMINE THE FUNCTION OF THE LIBRARY RANDOM FOR THE SPECIFIED TASK;
12.6.1.3 IDENTIFY CODE SNIPPETS THAT USE RANDOM SEQUENCE GENERATION;
12.6.1.4 SOLVE PROBLEMS USING RANDOM NUMBERS AND RANDOM SEQUENCES;
Let’s remember!
HTTPS://WWW.YOUTUBE.COM/WATCH?V=KZQSDVZOFNA
WHAT THE FUNCTION DOES?
Function What it does
randint(x, y) Generates a random integer from x to y, including the x and y.
randrange(start, stop,
Generates a random integer in the range(start, stop, step)
step)
random() Generates a random floating-point number in the interval [0,1)
• The string module contains various string constant which contains the
ASCII characters of all cases. It has separate constants for lowercase,
uppercase letters, digits, and special symbols, which we use as a
source to generate a random string.
Pass string constants as a source of randomness to the random module
to create a random string
TASK 1 ”STRING"
Write a program
• to pick a random character from a given String.
• 3 unique random character from a given String.
• 3 random characters with replacement from a given String.
Example.
Input: University
Random output: s, n e r, UiU
TASK 2 ENCRYPTION PROGRAM
Note: String must be the combination of the UPPER case and lower case letters only. No
numbers and a special symbol.
Example
Output: Random String is sWdRF
TASK 4 “PASSWORD” (ADVANCED LEVEL)