While loop- printTable
Easy Accuracy: 58.02% Submissions: 13069 Points: 2
While loop is another loop like for loop but unlike for loop it only checks for one condition.
Here, we will use while loop and print a number n's table in reverse order.
Example 1:
Input: n = 1 Output: 10 9 8 7 6 5 4 3 2 1
Example 2:
Input: n = 2
Output: 20 18 16 14 12 10 8 6 4 2
https://youtu.be/QY7fDniYjmA
#User function Template for python3
class Solution:
def printTable(self, n):
multiplier = 10
while(multiplier):
print(multiplier * n, end = " ")
multiplier -= 1
print()
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__ == '__main__':
T=int(input())
for i in range(T):
n = int(input())
obj = Solution()
obj.printTable(n)
# } Driver Code Ends
Comments
Post a Comment