DEV Community

Justin Loertscher
Justin Loertscher

Posted on

My first scanning code

This is one of my first projects with Codecademy and here is my code not code. Well it's at least my Psudocode. Let me know where I went wrong. I really would appreciate the help.
Cheers

define text=
define pattern=
set if checked boolean= False
set if has pattern boolean= False

has text been checked?
no:
if text hasn't been checked:
scan for pattern in text
if pattern found set pattern found boolean = true
once text is scanned set text check boolean = true

Yes: print results, pattern found = true/false
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
nlxdodge profile image
NLxDoDge

Hi, first of all welcome to DEV.to 🙌🏻

I suppose from the pyth tag in your post that you want to learn Python?
W3Schools has you covered, on W3School you can learn more about how Python variables specifically work as well.

But the good part is. If you click on any of the Try it yourself buttons you get use a free Python interpreter without installing anything on your computer. For example: w3schools.com/python/trypython.asp...

Has the following code:

x = 5
y = "John"
print(x)
print(y)
Enter fullscreen mode Exit fullscreen mode

This will do variable assignment like you mentioned above. So to convert your pseudocode somewhat to python it might be like this:

text = "Hello World!"
pattern = "ello"

checked = False
has_pattern = False

if checked == False: # here you check if string hasn't been checked yet
    if pattern in text: # here we check if the pattern is in the text variable
        pattern = True # we set pattern to true here
    checked = True # we set checked here and not at the same "width" as pattern. Else it if the pattern is not in the text it would also not set checked to True if it wasn't in the spot that it's in right now.
Enter fullscreen mode Exit fullscreen mode

Happy Learning 😎