# Function to calculate the sum of cubes of the first n integers and show the formuladef sum_of_cubes(n):cubes = [i**3 for i in range(1, n + 1)]sum_cubes = sum(cubes)return sum_cubes, cubes# Function to calculate the square of the sum of the first n integers and show the formuladef square_of_sum(n):numbers = list(range(1, n + 1))sum_of_numbers = sum(numbers)square_sum = sum_of_numbers ** 2return square_sum, numbers# Prompt user for the number of lines to printtry:limit = int(input("How many numbers would you like to print? "))if limit > 0:for n in range(1, limit + 1):# Sum of cubes calculation and outputsum_cubes, cubes = sum_of_cubes(n)cubes_formula = ' + '.join([f"{i}^3" for i in range(1, n + 1)])print(f"n = {n}: {cubes_formula} = {sum_cubes}", end=" ")# Square of sum calculation and outputsquare_sum, numbers = square_of_sum(n)numbers_formula = ' + '.join([str(i) for i in range(1, n + 1)])print(f"({numbers_formula})^2 = {square_sum}")print() # Blank line between the resultselse:print("Please enter a positive integer.")except ValueError:print("Invalid input! Please enter a valid integer.")