Print a mirror image of a right-angled triangle using '*'. See examples for more details.Input FormatThe First line of input contains T - the number of test cases. It's followed by T lines, each line contains a single integer N - the size of the pattern.Output FormatFor each test case, print the test case number as shown, followed by the pattern, separated by a new line.Constraints1 <= T <= 1001 <= N <= 100ExampleInput421510OutputCase #1: ***Case #2:*Case #3: * ** *** *********Case #4: * ** *** **** ***** ****** ******* ******** *******************
Question
Print a mirror image of a right-angled triangle using '*'. See examples for more details.Input FormatThe First line of input contains T - the number of test cases. It's followed by T lines, each line contains a single integer N - the size of the pattern.Output FormatFor each test case, print the test case number as shown, followed by the pattern, separated by a new line.Constraints1 <= T <= 1001 <= N <= 100ExampleInput421510OutputCase #1: ***Case #2:*Case #3: * ** *** *********Case #4: * ** *** **** ***** ****** ******* ******** *******************
Solution
Here is a Python solution for the problem:
T = int(input())
for t in range(1, T+1):
N = int(input())
print(f'Case #{t}:')
for i in range(1, N+1):
print(' ' * (N-i) + '*' * i)
This script works as follows:
- It first reads the number of test cases,
T. - Then it enters a loop that runs
Ttimes. For each iteration, it does the following:- It reads the size of the pattern,
N. - It prints the case number.
- It enters another loop that runs
Ntimes. For each iteration, it does the following:- It prints a string that consists of
N-ispaces followed byiasterisks, whereiis the current iteration number. This creates the mirror image of a right-angled triangle.
- It prints a string that consists of
- It reads the size of the pattern,
Please note that the input should be provided in the following format:
4
2
1
5
10
This means that there are 4 test cases. The size of the pattern for the first test case is 2, for the second test case is 1, for the third test case is 5, and for the fourth test case is 10.
Similar Questions
Print Hollow Diamond PatternPrint a hollow diamond pattern using '*'. See examples for more details.Input FormatThe first line of input contains T - the number of test cases. It is followed by T lines, each line contains a single odd integer N - the size of the diamond.Output FormatFor each test case, print the test case number as shown, followed by the diamond pattern, separated by a new line.Constraints1 <= T <= 1003 <= N <= 201ExampleInput437515OutputCase #1: ** * *Case #2: * * * * ** * * * * * *Case #3: * * ** * * * *Case #4: * * * * * * * * * * * * ** * * * * * * * * * * * * * *
Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each line contains 2 numbers N and P, separated by space.Output FormatFor each test case, print the value of N % P, separated by a new line.Constraints20 points1 <= T <= 1001 <= N <= 10181 <= P <= 10880 points1 <= T <= 1001 <= N <= 10100001 <= P <= 1015ExampleInput45 24 101085377843 817659438290826691135830692772803 95972011Output142242058460316167
You have a collection of N rods. Each rod has a unique mark on it. You are given the lengths of each rod. You have to tell how many different triangles can be formed using these rods.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines, the first line contains N - the number of rods. The second line contains the lengths of the rods.Output FormatFor each test case, print the total number of different triangles possible, separated by new line.Constraints30 points1 <= T <= 1001 <= N <= 1001 <= A[i] <= 10000070 points1 <= T <= 1001 <= N <= 10001 <= A[i] <= 100000ExampleInput2620 67 72 83 23 5964 2 10 12 8 10Output1410
Given an Integer N, write a program to reverse it.InputThe first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.OutputFor each test case, display the reverse of the given number N, in a new line.Constraints1 ≤ T ≤ 10001 ≤ N ≤ 1000000Sample 1:InputOutput41234531203212323005432130213321232
Given a number, swap the adjacent bits in the binary representation of the number, and print the new number formed after swapping.Input FormatThe first line of input contains T - the number of test cases. Each of the next T lines contains a number N.Output FormatFor each test case, print the new integer formed after swapping adjacent bits, separated by a new line.Constraints1 <= T <= 1000000 <= N <= 109ExampleInput410743100Output51123152
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.