American Young Coder (AYC)

AYC logo
Loading Events

« All Events

  • This event has passed.

6:30pm – Intro to Python – Roland

May 7 @ 6:30 pm - 7:30 pm

Today We Did

        1. Reviewed HW
          1. the list goes inside the parenthesis of random.choice
        2. Function Review Exercises
          1. Problem 1 & 2 from HW
          2. Challenge Problem 3, using random.randint to get a random item from list instead of random.choice
        3. Password generator
          1. see PasswordGenerator.py in the notes folder on Google Drive

Homework:

Submit the following file into your Google Drive Homework Folder

      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)
        1. Exercise 1:
          1. Create a function called “starwars”, no parameter.
            1. Create a new variable (“robots”)
            2. The value of this”robots” variable is: “R2-D2”, “C-3PO”, “ASN-121”.
            3. 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.
              1. R2-D2
                C-3PO
                ASN-121
        2. Exercise 2:
          1. Create a function called “starwars2”. no parameter.
            1. Create a new variable (“robots”)
            2. The value of this “robots” variable is: “R2-D2”, “C-3PO”, “ASN-121”, “WALL-E”, “DATA”, “BUMBLE-BEE”.
            3. Using random module, choose a random element from the list. print this random element to the shell.
        3. Exercise 3:
          1. Create a function called “starwars3”, one parameter (“suffix”)
          2. Copy the code from “starwars2” function into “starwars3” function.
          3. Instead of just printing the robot name, combine the robot name with the parameter “suffix”
          4. For example, if a user calls the function like the following
          5. Call the function like this
            starwars3(" is the best")
            starwars3(" is my friend")
          6. 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
            1. C-3PO is the best 
              
              R2-D2 is my friend
        4. Create a function “starwars_weapon”. one parameter, “type”
          1. if “type” parameter is “small”, the function will return one of these weapons randomly: light saber, blaster pistol, sonic pistol
          2. if “type” parameter is “big”, the function will return one of these weapons randomly: blaster cannon, missile launcher, plasma cannon.
          3. call the function, get the return value and print to the shell.

If you have any questions, feel free to email me at rolandyang@ayclogic.com

Details

Date:
May 7
Time:
6:30 pm - 7:30 pm
Verified by MonsterInsights