Question

In python 3What you need to do? 1. 2. 3. Create a function implementing the logic to a Pascal triangle. (You can use any logic of your choice to generate the triangle) Read an integer input from the user, to determine the number of rows to be generated in a Pascal triangle. Call the function by passing the input as an argument to the function. Hint: You can use a list of lists to store the values of a Pascal triangle. Sample Output: Enter a value: 7 14641 1 510 10 51 16 1520 15 61 Hit enter to end the program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

n=int(input("Enter value: "))
list=[1]
for i in range(n):
for ll in range(len(list)):
print(list[ll],end=" ")
newlist=[]
newlist.append(list[0])
for i in range(len(list)-1):
newlist.append(list[i]+list[i+1])
newlist.append(list[-1])
list=newlist
print()

n-int(input (Enter value: )) for i in range(n): for 1l in range(len(list)): print (list[11],end-) newlist-[] newlist.append (list[0]) for i in range(len(list)-1): newlist.append (list[i]+list[i+1]) newlist.append (1ist[-1]) list-newlist print() CAUsersrishiraj AppData\Local\Programs Python Python371p nter value: 2 1 3 3 1 4 6 4 1 5 10 10 5 1 6 15 20 15 6 1

////////////////////////using function///////////////////////////


def triangle(n):
list=[1]
for i in range(n):
for ll in range(len(list)):
print(list[ll],end=" ")
newlist=[]
newlist.append(list[0])
for i in range(len(list)-1):
newlist.append(list[i]+list[i+1])
newlist.append(list[-1])
list=newlist
print()

n=int(input("Enter value: "))
triangle(n)

Add a comment
Know the answer?
Add Answer to:
In python 3 What you need to do? 1. 2. 3. Create a function implementing the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT