# Define a list of integers
numbers = [10, 20, 30, 40, 50]
# Compute the sum of all integers
sum_of_numbers = sum(numbers)
# Print the sum
print("Sum of integers:", sum_of_numbers)
3.3.4 Hack 1 Javascript:
%%js
function calculateToThirtyTwo() {
const a = 8; // you can adjust these values
const b = 4; // you can adjust these values
const result = (a * b) + (b * b) - (b / b);
return result; // returns 32
}
console.log(calculateToThirtyTwo()); // Output: 32
3.3.3 Hw #1 Python:
def calculate_mean_median():
# Define a list of integers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# Compute the arithmetic mean
mean = sum(numbers) / len(numbers)
# Compute the median
numbers.sort()
mid = len(numbers) // 2
if len(numbers) % 2 == 0:
median = (numbers[mid - 1] + numbers[mid]) / 2
else:
median = numbers[mid]
# Print both results
print("Mean:", mean)
print("Median:", median)
# Call the function
calculate_mean_median()
Hw 2 Python:
def collatz_sequence(a):
# Initialize the sequence with the starting number
sequence = [a]
# Generate the Collatz sequence
while a != 1:
if a % 2 == 0:
a = a // 2
else:
a = 3 * a + 1
sequence.append(a)
# Print the sequence
print("Collatz sequence:", sequence)
# Example usage
collatz_sequence(7)