« All Events
7PM Python Level 1
November 2, 2018 @ 6:00 pm - 7:00 pm
- We went over Homework October 19.py
- We went over Homework Magic8Ball.py
- Python Quiz next week November 10, 2018
- Please study Last Quiz (3 weeks) ago.
- Please study Homework October 19
- Please study Homework Magic8Ball.py
- Please study how to use List, how to print element inside a List.
- Some exercises to prepare for the test
- Exercise 1:
- Create a function called “printSomething()”
- Inside the function generate a random number between 1 to 4 and set/save it into variable called “randomNum”.
- If computer pick number 1, then print “Hi number one is cool.”
- If computer pick number 2, then print “Number two is cooler.”
- Everything else then print “<randomNum> is the best”.
- Call the function.
- Exercise 2:
- Create a python function name “subtractTwoNumbers” takes 2 parameters. Subtract 1st parameter with the 2nd parameter and return the value.
- Call the function and set/save return value to a variable call “result”.
- And then print “Result of subtraction is <whatever the result from the function>”
- For example, if I call the function like the following “subtractTwoNumbers(10,2)” , “result” variable will have a value of 8 and the print will print “Result of subtraction is 8”.
- Exercise 3:
- Create a function called “starwars”, no parameter.
- Create a variable with data type List of String call it “robots”.
- The value of this”robots” variable is: “R2-D2”, “C-3PO”, “ASN-121”.
- print each of these name using the list inside this function.
- Call this starwars function. When I call, it will print the following from inside the function.
R2-D2
C-3PO
ASN-121
- Exercise 4:
- Create a function called “starwars2”. no parameter.
- Create a variable with data type List of String call it “robots”.
- The value of this “robots” variable is: “R2-D2”, “C-3PO”, “ASN-121”.
- Generate a random number between 0 to 2 and set it into a variable called “idx”.
- Use this “idx” variable to print one of the elements inside the List. For example, if “idx” is 0, the function will then print “R2-D2”. If “idx” is 1, then the function will print “C-3PO”.
- Exercise 5:
- Create a function called “starwars3”, one parameter.
- Copy the code from “starwars2” function into “starwars3” function.
- Instead of just printing the robot name, combine the robot name with the parameter.
- For example, if user call the function like the following
starwars3(" is the best")- And if the computer pick random number 1, then it will print
C-3PO is the best