« All Events
7PM Python Level 1
November 30, 2018 @ 6:00 pm - 7:00 pm
- We went over the Stary Night homework.
- We completed Stary Night project from page 90 to 96.
- We learned the difference between “random.randrange” and “random.randint”.
- We learned how to choose random element inside a list using random index and random.choice.
- We learned how to create star in the Stary Night project by clicking.
- Homeworks:
- Create a python file call it “MegaRandom.py”
- Create a variable data type is list of string call it “gospel” and the value would be “Matthew”, “Mark”, “Luke”, “John”.
- Create a function call it “giveMeRandomGospel1” with no parameter.
- In this function return a random element from list “gospel”. Use “random.randrint” to select a random element from the list.
- Call this function and concatenate the result with “Random gospel1 = ” and print the result to the screen.
- For example, the result could be something like the following if you call the function twice and print the result twice
Random gospel1 = Mark
Random gospel1 = John
- Create a function call it “giveMeRandomGospel2” with no parameter.
- In this function return a random element from list “gospel”. DO NOT use “random.randint” to select a random element from the list. Look at previous class to see which other random function you can use to select random element from list.
- Call this function and concatenate the result with “Random gospel2 = ” and print the result to the screen.
- For example, the result could be something like the following if you call the function twice and print the result twice
Random gospel2 = Mark
Random gospel2 = John
- Modify the previous homework file “stary_night.py” to do the following
- Create a new function call it “draw_planet” with 4 parameters: size, color, x, y.
- Look at page 97 on how to create “draw_planet” function. Inside the book the size of the circle is always 50. Modify the size of the circle to be according to parameter size.
- In the project, inside the loop which creates the random stars, modify the code so it will do the following
- IF random.randint(1,2) == 1 call “draw_planet” function ELSE call “draw_star” function.