CBSE Class 11 Computer Science Question 100 of 106

Python Fundamentals — Question 9

Back to all questions
9
Question

Question 9

Write a program to read a number n and print n2, n3 and n4.

Solution
n = int(input("Enter n: "))
n2, n3, n4 = n ** 2, n ** 3, n ** 4
print("n =", n)
print("n^2 =", n2)
print("n^3 =", n3)
print("n^4 =", n4)
Output
Enter n: 2
n = 2
n^2 = 4
n^3 = 8
n^4 = 16
Answer