Srinivas Dusa
Srinivas Dusa
Aspiring MERN Stack Developer | CCBPian at NxtWave | Python, SQL, React JS
Published May 26, 2022
N = int[input[] for counter in range[N]: print["* " * [counter+1]] for counter in range[N]: print["* " * [counter+1]]]
-
javascript
Aug 11, 2022
-
modern js-rest operator
Jul 28, 2022
-
finding mondays in the years - python working with datetime class
Jun 18, 2022
-
composition [used instance of one class as attribute in another class] and overriding [calling the same function in the subclass but using the super[]
Jun 16, 2022
-
first and second digit equal program -python
Jun 13, 2022
-
word cound using dictionary in python - without duplicate values.
Jun 12, 2022
-
fibonacci series using recursion which call the function itself - python program
Jun 8, 2022
-
list methods - python
Jun 8, 2022
-
factorial of a number in python
Jun 7, 2022
-
string of numbers to get the max number using python program
Jun 7, 2022
Others also viewed
Explore topics
In this shot, we will discuss how to generate a solid right-angled triangle using alphabets in Python.
We can print a plethora of patterns using Python. The essential and only prerequisite is a good understanding of how loops work in Python. Here, we
will be using simple for
loops to generate solid right-angled triangles using alphabets.
Description
A triangle is said to be right-angled if it has an angle equal to 90 degrees on its left side.
To execute the same using Python programming, we will be using two for
loops:
- An outer loop to handle the number of rows.
- An inner loop to handle the number of columns.
Code
Let’s have a look at the code.
# Number of rows rows = 8 # Outer loop to handle the rows for i in range[rows]: # Inner loop to handle the columns for j in range[i + 1]: ch = chr[65+i] # Printing the pattern print[ch, end=' '] # Next Line print[]
Example code generating a solid right-angled triangle using alphabets
Explanation
In line 2, we take the input for the number of rows [i.e., triangle length].
In line 5, we create a
for
loop to iterate through the number of rows.In line 8, we create an inner nested
for
loop to iterate through the number of columns.In line 9, we define
ch
, which is used to create alphabets from numbers by using the iterative value ofi
and the concept of ASCII conversion. The starting value65+[i=0]
has been used, as the ASCII value ofA
[starting of the triangle] is65
.In line 11, we print the pattern [here, alphabets]. Any other characters could have been printed by mentioning the same in the print statement. The end statement helps us stay on the same line until the loop finishes.
In line 14, we use
print[]
to move to the next line.
RELATED TAGS
communitycreator
python
alphabets
triangle
Solid Right Angled Triangle - 2
This Program name is Solid Right Angled Triangle - 2. Write a Python program to Solid Right Angled Triangle - 2, it has two test cases
The below link contains Solid Right Angled Triangle - 2 question, explanation and test cases
//drive.google.com/file/d/1FoDyc8wQxsu918bAHA-Va4WSfPZTSZ9e/view?usp=sharing
We need exact output when the code was run
Solid Right Angled Triangle - 2
This Program name is Solid Right Angled Triangle - 2. Write a Python program to Solid Right Angled Triangle - 2, it has two test cases
The below link contains Solid Right Angled Triangle - 2 question, explanation and test cases
//drive.google.com/file/d/1wZHjOSToDFKleclnKLf2md1FclvO7EWq/view?usp=sharing
We need exact output when the code was run