Pages

Python 100 Days


Day 1

string variables have methods, like:

print(var1.upper())

print (var2.title())

f-string -- stands for format-string

Put variables inside a string.

print(f"Hello {var} World")

python3 command, if you use it to run a script:

#! line isn't needed

chmod u+x isn't needed

$python3 hello.py

Day 2

1_000 is the same as 1000, just can make numbers easier to read.

import this #Zen of Python, principle for coding

[list] are in brackets

#not much today since it is Thanksgiving

Day 3

Reviewed the chapter on list (from Python Crash Course book, I’ll get the right title later). I didn’t clock any keyboard time; holiday is interrupting my fun. :)

Day 4

Saturday, Nov 30th. No Python today.

Day 5

Small script to count to 1 million using range, and finding the min, max, and sum of the range.

my_var = range(0, 5) # Now it's a range object
my_var = list(my_var) # Now it's a list

I was getting confused when to use [ brackets ] and when to use (parentheses). If using the list() function, then parentheses are needed. If calling a [list] directly, then brackets. And you can’t use the range object by itself and expect it to be a list. You must change the type of the variable from a range object to a list object by using the list() function.

Day 6

Used ChatGTP-canvas to create a script to pull down NFL website to check for today's game schedule. The program ran without error, but the webpage was more difficult to search than my skill level to ask chat what to do. I'll work on it more.

Day 7

I'm not getting in the practice required - or the practice I want. Rearranging my day schedule to make room.

How about a short script to replace my "start here" idea?

input() function always returns a string.

  • must convert to integer if needed
    • age = int(input("How old are you? "))
    • print(f"You are {age} years old.")

wrote a response checking function:

def response(question):
	positive_responses = {"y", "yes", "sure", "i did", "yep", "of course"}
	negative_responses = {"n", "no", "not yet", "nope", "nah"}
	
	print() #blank link before responses
	answer = input(question).strip().lower()

	if answer in positive_responses:
	    print("Confirmed. Please continue\n")
	elif answer in negative_responses:
	    print("Please act before proceeding.\n")
	    sys.exit(0)
	else:
	    print("I didn't quite understand that.")

I can add questions as needed:

response("Have you checked all schedules for today?")
response("Have you identified important task(s) for today?")

Tomorrow I'll add pytest() to check functions.

Day 8 - Wednesday Dec 4th

Tuples are like list but are immutable.

Create with () and then use [] to interact with a tuple.

You can't change a tuple, but you can reset with new values.

Like ranges, lists are off by one; meaning they stop before the number mentioned in the slice: [0:4] will print 0,1,2,3 but not 4.

To copy a list, you can make a whole slice; otherwise, you set a list equal to a list and you'll have two list variables pointing to the same list of data.

new_list = old_list[:] to copy.

PEP8

  • limit code to less than 80
  • limit comments to 72 (some tools add characters, so leave room)

Day 9

Made it through Chapter 5.

Empty strings evaluate to false.

use sys.argv[] for simple command line argument passing. There are better ways if the arguments get more complex.

sys.agrv is a type of string. Need to change type as needed.