1 September 2022
notes
There wasn't really any lecture. Mr. Yeoung (not sure how to spell his name) introduced us to the "reflections on computer science" page and I read most of it. I'll put some things that I learn from the page here
import random
ranumber = random.randrange(20)
print(ranumber)
print(ranumber)
def for_loop():
print("For loop output\n")
from doctest import OutputChecker
import random
from subprocess import check_output
from IPython.display import clear_output
ranumlist = []
list4 = [1, 2, 3, 4, 5]
n4 = (4)
n10 = (10)
oddNum = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
n0 = [0]
n1 = [1]
oddbool = [0]
def for_loop():
print("For loop output\n")
for n4 in list4:
ranumber = random.randrange(20)
ranumlist.append (ranumber)
for_loop()
def odd_test():
if ranumlist[0] == oddNum[n0[0]]:
oddbool[0] = oddbool[0] + 1
else:
n1 = (1)
def add_loop():
print("Add loop output\n")
for n4 in n1:
n0[0] = n0[0] + 1
def num_loop():
print("Number loop output\n")
for n10 in oddNum:
odd_test()
add_loop()
print(ranumlist)
print(ranumlist[0])
num_loop()
if oddbool[0] == 1:
print("odd")
else:
print("even")
print(n0)
print(oddbool[0])
msg = (20)
lsit = []
lsit.append (msg)
print(lsit)
After Code
I have just finished the odd number test, it took about 3 classes to finish. It took a bit but the odd number test works and I'm very glad. This was a very fun thing to work on, it wasn't an assignment for class, it was just something I started out of curiosity of "can I do it" and finished because I had fun trying to figure out how to do it. Technically it's not complete, the last bit of the code I want is to clear the output so only the print(oddbool) bit is printed but I haven't figured out how to do that yet. For now, it's finished but not polished.
I want to get a little more into the code, so I can show how I did it and why it could be weird looking. The first bit is the imports but that's not too important. They were a random number generator, an output checker, and an output clearer. I only ended up using the random generator because I couldn't figure out how to work the other two. Now I'll get into the real code.
The first bit is the lists and variables. I slowly put more and more in as I continued coding, each has a purpose; ranumlist is the list that contains the randomly generated numbers, they're appended later on so they're always different. list4 was for the for_loop. I think it originally contained only four numbers so the for_loop would loop 4 times but I'm not sure. n4 is a variable for 4, it was also for the for_loop with the same reason as list4. Honestly, I never really figured out how the loops worked. I don't know how the variables and lists affect the for loop when defining it. n10 is for the num_loop, it was created to loop num_loop 10 times for each of the odd numbers, I'll get into that later. oddNum is a list of all the odd numbers that can be generated, this is so I can compare each number to the number generated. n0 is a very important piece of the code. n0 is used to choose a list item from oddNum. Later I will explain how it plays into the code. n1 is an empty variable. It actually equals 1 but it's only used to fill space in an if else statement. Last is oddbool, it's used to tell another chunk of code if the number is odd.
The for_loop is the first chunk of code. It's used to add random numbers to ranumlist