#🔒 what can I do? quick question

23 messages · Page 1 of 1 (latest)

clear surge
#

I have a question, let’s say I get a huge block of integers and I have to do a corresponding task depending on the integer I will use a for loop and if, but how can I scan every single integer?

crisp cryptBOT
#

@clear surge

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.

safe grail
#

what do you mean by "scan"?

#

and what do you mean by "block"?

clear surge
#

Here’s an example of what I mean by a block of integers

#

2 4 1 3 4 3 2 1 1 3 2 4 4 1 3 2 3 4 2 1 2 4 3 1 3 2 1 4 2 3 1 4 3 2 4 1 3 2 1 4 3 2 4 3 1 2 4 1 3 2 1 4 3 1 4 2 3 2 1 4 3 2 4 1 3 1 2 3 4 1 4 2 3 3 4 2 1 4 1 3 2 2 4 3 1 1 2 3 4 4 3 1 2 3 2 1 4 1 3 2

#

So for example I want my code to check each digit

#

Each digit has a corresponding action

safe grail
#

i'd suggest putting them in a text file and then reading and parsing the file

clear surge
#

Parsing?

safe grail
#

general term for transforming an input into something you can use

#

are you familiar with opening files with python?

clear surge
#

No

safe grail
#
with open("path/to/myfile.txt") as file:
    for line in file:  # line is a string representing each line in the file
        numbers = line.split()  # splitting that string by spaces into a list of the numbers (as strings)
#

the path to the file is relative to your current working directory

clear surge
#

Then I can turn the strings into int?

stark hinge
#

If all you need to do is correspond a value to some sort of action, then it doesn't necessarily need to be int

#

unless you're using them to index a list of actions

safe grail
#

but yes, you could if you really need to

clear surge
#

I mean like I want to set a value = 0 then depending on the number either 2, 4 would do west and east so it’s coordinates would change

#

So I want my program to check every number so it can assign the new position

crisp cryptBOT
#
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.