3.14 and 3.15 Hacks
import random
def generate_random_numbers(n):
# Create empty lists for even and odd numbers
even_numbers = []
odd_numbers = []
# Generate n random numbers
for i in range(n):
# Generate a random number between 1 and 100
number = random.randint(1, 100)
# If the number is even, add it to the list of even numbers
if number % 2 == 0:
even_numbers.append(number)
# If the number is odd, add it to the list of odd numbers
else:
odd_numbers.append(number)
# Return the lists of even and odd numbers
return even_numbers, odd_numbers
# Generate 10 random numbers
even_numbers, odd_numbers = generate_random_numbers(10)
# Print the lists of even and odd numbers
print("Even numbers:", even_numbers)
print("Odd numbers:", odd_numbers)
import numpy as np
# Create a NumPy polynomial object representing the function
# 2x^5 - 6x^2 + 24x
poly = np.poly1d([2, 0, -6, 24, 0])
# Find the derivative of the polynomial
derivative = np.polyder(poly)
# Print the derivative
print(derivative)
import numpy as np
# Create a NumPy polynomial object representing the function
# (13x^4 + 4x^2) / 2
poly = np.poly1d([13, 0, 4, 0, 0], True)
# Find the derivative of the polynomial
derivative = np.polyder(poly)
# Evaluate the derivative at x = 9
derivative_at_9 = derivative(9)
# Print the derivative at x = 9
print(derivative_at_9)
animals = ["dog" for _ in range(10)] + ["cat" for _ in range(10)]
# Use the random.shuffle() function to shuffle the list in place
import random
random.shuffle(animals)
# Print the shuffled list of animals
print(animals)
This code will generate a list of 20 animals (10 dogs and 10 cats) and then use the random.shuffle() function from the Python random module to shuffle the list in place, resulting in a random order for the animals.