ycl session 7 bookmark these libraries libraries a
play

YCL Session 7 Bookmark these libraries! Libraries A library is a - PowerPoint PPT Presentation

YCL Session 7 Bookmark these libraries! Libraries A library is a collection of code for functions and classes. Module(s) Another term used to describe a library of code is module. The Random Library Random numbers are heavily used in


  1. YCL Session 7 Bookmark these libraries!

  2. Libraries A library is a collection of code for functions and classes.

  3. Module(s) Another term used to describe a library of code is module.

  4. The Random Library Random numbers are heavily used in computer science for programs that involve games or simulations. #import library at top of each script import random

  5. Code Snippet #1 #import the random library import random #generate a random number from 0 to 49 my_number = random.randrange (50) #print the randomly generated number print(my_number)

  6. Code Snippet #2 #import the random library import random #generate a random number from 100 to 200 my_number = random.randrange (100, 201) #print the randomly generated number print(my_number)

  7. Activity: Magic 8 Ball 1. Create a file called magic_8_ball.py in a Session 7 directory. 2. Import the random library and the system library (sys). 3. Ask for a user’s input and save it in a variable called question for example. You’ll use this variable to start your chain of conditionals. If the question is blank, the game should exit (use sys!). 4. Else, the user should get a randomly generated answer. To accomplish this, you will need the same number of elif statements and print statements as the number of random integers you are generating. So if you are generating integers between 1 and 6 (inclusive if you use random.randint(1, 6), you will need six elif’s and six print statements! 5. Put everything into a while True loop.

  8. HINT for the BONUS

  9. HINT for the BONUS You will need one additional command to create and display your text output to the Arcade game window, which can go wherever you are drawing and rendering the rest of your drawing: render_text(), which takes four arguments: 1. a create_text() module 2. a starting x coordinate 3. A starting y coordinate 4. A rotation number This might look something like this: 1. arcade.render_text(text=arcade.create_text( 'NO' ,arcade.color.BLACK), 2. start_x=400, 3. start_y=300, 4. rotation=0)

  10. Pair Programming

Recommend


More recommend