A project in Python

I can’t tell you how many videos and books and articles I’ve consumed on Python. At first I was driving myself even crazier because I was also doing the same for Swift code. But I stopped Swift and have been focusing on Python. Unsure if I’m making progress. Not really, no.

I’ll follow along with a video, do the code on my mac or iPad, and all is good. I’ll tweak it here and there and watch what happens. But generally it’s all not sinking in. I tried to take some killer Notion apps, like I see on YouTube. But I cannot access Notion the 8 hours I’m in an office, and the internet is sometimes too slow to access it on my MBP or iPad when I’m out of the Operations Center and its lame computer/network.

Earlier I had Googled for some beginner projects. I liked the one for choose your own adventure. I did a simple choice last week where it asked about pineapple and pizza. This time I started from scratch and started to move down a path.

One thing that is strange to me is that when I put in this:

name = input("What is your name?").strip()

print(name, ", before you is an old gate. It appears to be quite old, with vines snarled around the bars so thickly that you cannot see through to the other side.")

I get a space after the name variable when I have it in a string.

That little space after my name and before the comma drives me nuts. But I’ll hold off on that detail. For now I’m pressing on. Let’s add some loops. I saw in one video how you can add the .lower() and it will take a YES or Yes and convert it all to a lowercase ‘yes’. Otherwise, I’d have to write some code checking for this in the loop. Neat trick.

I’ll admit that I goofed when I made this at first. I was testing it with each step of the way, and before I wrote the else at the end, it was an infinite loop and kept printing the last sentence a bazillion times and crashed Safari. HA! I added the else and it fixed it.

I wanted a way to keep track of progress, and right off the top of my head I named it block and gave it a value of 1. I used a simple += 1 with it and figured that I could do some while loops for various values of the block. Because this was a local variable, I had to use the global keyword. Not that I’m smart here, but I didn’t know how else to increment the variable up one as a result of a choice, but also have that variable defined outside of the function. This seems to work just fine.

Published by Eddie

I'm a goofball. I like Doctor Who, Star Wars (yes, all of them), and of course Firefly. I think that "Out of Gas" from Firefly is the single greatest episode of any SciFi. Closely followed by "All Great Things..." from Star Trek: The Next Generation. I'm an Apple geek. Seriously, I brought a 2013 MBP and two iPads with me on deployment. Every year I watch all the Apple Keynotes. Someday I'd like to learn Swift, as I've got some ideas for some useful apps that I'd like to use. One might find me at a coffee shop, at the LGS getting more Magic: The Gathering cards, on some trail in the mountains of Oregon, on one of my Macs, running a trail, or who knows.

One thought on “A project in Python

  1. Can’t sleep. Was thinking about this code. Opened this up and immediately saw an error. The second block += isn’t set to global. Therefore it creates another block variable, only this one is local.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: