+ 1

Python program question

Write a Python program that allows the user to enter any integer value, and displays the value of 2 raised to that power. Your program should function as shown below. What power of two? 10 Two to the power of 10 is 1024

7th Feb 2017, 5:59 AM
Atitebi Jacob
Atitebi Jacob - avatar
3 Answers
+ 2
number = int(input("Enter a number: ")) print("2 to the power of", number, "is ->", 2**number)
7th Feb 2017, 6:14 AM
Kawaii
Kawaii - avatar
0
When you write the question: "What to the power of two? 10" with an answer of: "Two to the power of 10 is 1024" It doesn't really make sense, because: "What to the power of two? 10" Would be 10**2 or 10 * 10 by the way the question reads, and your answer: "Two to the power of 10 is 1024", suggests that you want 2**10 or 2*2*2*2*2*2*2*2*2*2 anyway: ans = int(input('What power of two? ')) print('Two to the power of', ans, 'is', 2**ans)
7th Feb 2017, 6:19 AM
ChaoticDawg
ChaoticDawg - avatar