- This event has passed.
6:30pm – Intro to Python – Roland
May 7 @ 6:30 pm - 7:30 pm
Today We Did
- Reviewed HW
- the list goes inside the parenthesis of random.choice
- Function Review Exercises
- Problem 1 & 2 from HW
- Challenge Problem 3, using random.randint to get a random item from list instead of random.choice
- Password generator
- see PasswordGenerator.py in the notes folder on Google Drive
- Reviewed HW
Homework:
Submit the following file into your Google Drive Homework Folder
- Make a new file called May7_FunctionRandomHW and complete the following exercises found at https://www.ayclogic.com/intro-to-python/star-wars-problem/ (also pasted below)
- Exercise 1:
- Create a function called “starwars”, no parameter.
- Create a new variable (“robots”)
- The value of this”robots” variable is: “R2-D2”, “C-3PO”, “ASN-121”.
- When this function is called, it will print all of the elements inside the list. Use “for loop” to go through each element inside the list.
R2-D2 C-3PO ASN-121
- Create a function called “starwars”, no parameter.
- Exercise 2:
- Create a function called “starwars2”. no parameter.
- Create a new variable (“robots”)
- The value of this “robots” variable is: “R2-D2”, “C-3PO”, “ASN-121”, “WALL-E”, “DATA”, “BUMBLE-BEE”.
- Using random module, choose a random element from the list. print this random element to the shell.
- Create a function called “starwars2”. no parameter.
- Exercise 3:
- Create a function called “starwars3”, one parameter (“suffix”)
- Copy the code from “starwars2” function into “starwars3” function.
- Instead of just printing the robot name, combine the robot name with the parameter “suffix”
- For example, if a user calls the function like the following
- Call the function like this
starwars3(" is the best") starwars3(" is my friend")
- And if the computer pick “C-3PO” for the first call and the second call the computer pick “R2-D2”, then in the shell, it will look like this
C-3PO is the best R2-D2 is my friend
- Create a function “starwars_weapon”. one parameter, “type”
- if “type” parameter is “small”, the function will return one of these weapons randomly: light saber, blaster pistol, sonic pistol
- if “type” parameter is “big”, the function will return one of these weapons randomly: blaster cannon, missile launcher, plasma cannon.
- call the function, get the return value and print to the shell.
- Exercise 1:
- Make a new file called May7_FunctionRandomHW and complete the following exercises found at https://www.ayclogic.com/intro-to-python/star-wars-problem/ (also pasted below)
If you have any questions, feel free to email me at rolandyang@ayclogic.com