

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Get K initial powers of N
When it is required to get the specific number of power of a number, the ‘**’ operator is used along with list comprehension.
Example
Below is a demonstration of the same
n = 4 print("The value n is : ") print(n) k = 5 print("The value of k is : ") print(k) result = [n ** index for index in range(0, k)] print("The square values of N till K : " ) print(result)
Output
The value n is : 4 The value of k is : 5 The square values of N till K : [1, 4, 16, 64, 256]
Explanation
The values for ‘n’ and ‘k’ are defined and are displayed on the console.
List comprehension is used to iterate through the numbers in the range of ‘k’.
The ‘**’ operator is used to get the power of the value.
This is assigned to a variable.
This is displayed as output on the console.
- Related Questions & Answers
- Python program to randomly create N Lists of K size
- Find k numbers which are powers of 2 and have sum N in C++
- PHP program to find the sum of the 5th powers of first n natural numbers
- PHP program to find the sum of the first n natural numbers who are not powers of a specific number ‘k’
- Program to find kth lexicographic sequence from 1 to n of size k Python
- C++ Program to get number at position k after positioning n natural numbers
- Python program to find N-sized substrings with K distinct characters
- Python - Consecutive Ranges of K greater than N
- Python Program to get K length groups with given summation
- Austin Powers in Python
- Sum of the series Kn + ( K(n-1) * (K-1)1 ) + ( K(n-2) * (K-1)2 ) + ... (K-1)n in C++
- Program to check whether number is a sum of powers of three in Python
- Program to find lexicographically smallest lowercase string of length k and distance n in Python
- Program to check n can be shown as sum of k or not in Python
- Python program to get all subsets having sum s\n
Advertisements