Pascal Triangle
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
...............
How to code the Pascal Triangle?
1. Understand the logic
2. Try to convert your logic into code. Again try... :)
3. Let's Code Now :)
Logic:
Each row's terms have a value of (n-1)Cr where n is the current line no and r is in range of [0, n-1]
1st Row:
1
0C0
2nd Row:
1 2 1
2C0 2C1 2C2
3rd row:
1 3 3 1
3C0 3C1 3C2 3C3
And so on ...
Python Stuff:
input(): This is used to take input in python. We can pass arguments to the input() function, this argument will be displayed on the console while taking input.
as: input("Good morning :)")
on the console: Good morning :)
num = int(input("Enter a number: ")): This is called typecasting in python. Input will be typecasted into int and stored in num variable. If the string is as input this will throw an error.
If you find the video helpful please like and subscribe :)
Happy Coding!
In questa pagina del sito puoi guardare il video online Code Pascal Triangle | Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato SantosH 22 dicembre 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 105 volte e gli è piaciuto 9 spettatori. Buona visione!