for fahrenheit in range(20, 51): celsius = fahrenheit_to_celsius(fahrenheit) print(fahrenheit, "F = ", round(celsius, 2), "C")
4.18
# get the input from the user
n = int(input("Enter a positive integer: "))
# initialize variables for the sums
sum_n = 0 sum_n_squared = 0 sum_n_cubed = 0
# loop over the range of numbers from 1 to n
for i in range(1, n+1): sum_n += i sum_n_squared += i ** 2 sum_n_cubed += i ** 3
# print the results
print("The sum of the first", n, "natural numbers is:", sum_n) print("The sum of the squares of the first", n, "natural numbers is:", sum_n_squared) print("The sum of the cubes of the first", n, "natural numbers is:", sum_n_cubed) 4.20
# initialize the matrix with zeros
matrix = [[0 for j in range(3)] for i in range(4)]
# loop over the rows and columns and calculate the value of each element for i in range(4): for j in range(3): matrix[i][j] = (i + j + 2) / (j + 1) ** 2