0

I would like to create a triangle and take user input from the user. I have already created the function for creating triangles.

Function:

def triangle(rows):
    PrintingList = list()
    for rownum in range (rows ):     
        PrintingList.append([])
        for iteration in range (rownum):
            newValue = raw_input()
            PrintingList[rownum].append(newValue)

But this takes input in this way..

3 
7
4
2 
4 
6
8 
5 
9 
3

I need it to take a input like this:

3 
7 4
2 4 6
8 5 9 3

How do it change it to take input in this way? need some guidance on this...

1
  • seems like a trick question in which the real goal is to flatten the input list back to the accepted input and continue... Commented Sep 1, 2012 at 17:53

1 Answer 1

4
for rownum in range (rows ):     
    PrintingList.append([])
    newValues = raw_input().strip().split()
    PrintingList[rownum] += newValues

I don't see here if you need or not to convert input from strings to ints.. But if you need, this will look like

for rownum in range (rows ):     
    PrintingList.append([])
    newValues = map(int, raw_input().strip().split())
    PrintingList[rownum] += newValues
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.