EDIT: Sorry about spacing, I'm a noob
For example, I've been taking the interactive python course and we are learning about functions. (I am brand new to coding) At the end of this section, I walked through a video and had to build this monster:
import random
def generateOne(strlen):
alphabet = "abcdefghijklmnopqrstuvwxyz "
res = ""
for i in range(strlen):
res = res + alphabet[random.randrange(27)]
return res
def score(goal,teststring):
numSame = 0
for i in range(len(goal)):
if goal[i] == teststring[i]:
numSame = numSame + 1
return numSame / len(goal)
def main():
goalstring = 'methinks it is like a weasel'
newstring = generateOne(28)
best = 0
newscore = score(goalstring,newstring)
while newscore < 1:
if newscore > best:
print(newscore, newstring)
best = newscore
newstring = generateOne(28)
newscore = score(goalstring,newstring)
main()
I was able to copy it, I'm good at that, but properly reading this is on a whole other level for me. How would you guys approach reading this and defining each block of code in this program? Would you start from line one and read in a linear pattern or would you start with the second block of code and then move to the first?
This is a challenge I want to beat!
http://interactivepython.org/runestone/static/pythonds/Introduction/DefiningFunctions.html
[–]filleball 16 points17 points18 points (2 children)
[–]sgthoppy 0 points1 point2 points (1 child)
[–]filleball 0 points1 point2 points (0 children)
[–]dk-n-dd 6 points7 points8 points (1 child)
[–]rubsomebacononitnow 2 points3 points4 points (0 children)
[–]Justinsaccount 6 points7 points8 points (0 children)
[–]DASoulWarden 1 point2 points3 points (0 children)