#๐Ÿ”’ How can I limit my output of the list to 6 values per line?

17 messages ยท Page 1 of 1 (latest)

junior stream
#

def get_data():
    ans = int(input("Input a 2 digit number: "))
    
    while (ans >= 100 or ans < 10):
        ans = int(input("Error, out of bounds, try again: "))
    
    new_list = []
    
    for i in range(0,ans):
        new_list.append(random.randint(10,99))
        
    return new_list

def print_data(num):
    l = get_data()
    
    print(len(l), "random values:", l)
    
    newl = []
    for i in range(0,len(l)):
        if (l[i] > num):
            newl.append(l[i])
    
    for i in range(0,len(newl)):
        print(newl[i], end=" ")    
    
    print('\n' + str(len(newl)), "values over", num)
                 
print_data(12)```
pure isleBOT
#

@junior stream

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

Hey @junior stream!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
maiden badge
junior stream
#

Like printing [:6] as the for loop iterates?

maiden badge
#

yes, you basically need to create what's called a "sliding window"

#

so you slice [0:6], then [6:12], then [12:18], and so on

#

do you see a pattern here?

#

the start increases by 6, and the stop is always start + 6

junior stream
#

i+6?

maiden badge
#

yes, so if you can create a loop that counts by 6, then you would slice [i:i + 6]

junior stream
#

Ty

#

.solved

maiden badge
#

it's with !

junior stream
#

!solved

pure isleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.