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.

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.
LikeLike