## Pursuing MSCS

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.
Note: posts here are not necessarily endorsed by the community, and may represent amateur or even bad practices.

### Pursuing MSCS

Hello,

I'm changing careers, will be obtaining an MSCS degree, probably taking a 3 1/2 to 4 year track

I have limited programming experience but I enjoyed FORTRAN at Auburn back in . . . 1983?

Anyway, I've been dabbling off & on, here and there, with Java & Python & whatever language is used with Arduinos (?) for the past ~8 years - all self-taught. As I'm in my mid-50's, this will probably be the last time I'll have an opportunity for an epic-career change so I'm taking this seriously.

I began programming again last Thursday and wrote two simple scripts (?) yesterday:

• Hourly vs. Annual Salary
• Guess the Number
• . . . misc other stuff . . .

I realize my methods aren't organized well, efficient, and so forth but I'm in "judo solution" mode - just making an effort to get it done, thinking I'll "fix it" later (ha). Having said that, any comments are most welcome - thank you!

Code: Select all
`import randomimport turtle as tstartX = 0startY = 0leaf_angle = 30leaf_size = 90size_incr = 45t.speed(0)t.pen(fillcolor="#008844", pencolor="green", pensize=2)def oh_yes():    leaf_angle = 340    leaf_size = 100    angle1 = 340    angle2 = angle1 - 180    for i in range(5):        t.penup()        t.goto(startX, startY)        t.pendown()        t.begin_fill()        t.setheading(angle1-38+(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.setheading(angle2-38+(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.penup()        t.end_fill()    for i in range(5):        t.penup()        t.goto(startX, startY)        t.pendown()        t.begin_fill()        t.setheading(angle1+218-(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.setheading(angle2+218-(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.penup()        t.end_fill()    t.pendown()    t.begin_fill()    t.setheading(275)    t.forward(leaf_size/2)    t.setheading(180)    t.forward(10)    t.goto(startX,startY)    t.setheading(90)    t.end_fill()    t.penup()for i in range(33):    startX = random.randrange(-250,250)    startY = random.randrange(-250,250)    oh_yes()`
Last edited by stranac on Sun Oct 20, 2013 1:46 pm, edited 1 time in total.
Reason: First post lock
When I'm in a difficult situation and there seems to be no possible solution, for some reason I always feel a little better, have a little more optimism when I remember the scene where George Jetson screams "Jane! Stop this crazy thing!"

millis

Posts: 9
Joined: Sun Oct 20, 2013 12:46 pm

### Re: Pursuing MSCS

That's pretty good actually, but here are some things I would change.

You are defining some things you overwrite before you ever use them. Why define things you don't need:
Code: Select all
`startX = 0startY = 0leaf_angle = 30leaf_size = 90size_incr = 45`

leaf_angle in the function is also never used.

These two loops are almost the same:
Code: Select all
`    for i in range(5):        t.penup()        t.goto(startX, startY)        t.pendown()        t.begin_fill()        t.setheading(angle1-38+(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.setheading(angle2-38+(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.penup()        t.end_fill()    for i in range(5):        t.penup()        t.goto(startX, startY)        t.pendown()        t.begin_fill()        t.setheading(angle1+218-(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.setheading(angle2+218-(i*32))        t.circle(leaf_size+(leaf_size*i*.25),40)        t.penup()        t.end_fill()`

I would just make the loop logic a function, and pass the different parts as parameters(just the 38 and 218 are different, as far as I can tell).
Maybe even just pass 'left' or 'right', and select an angle based on that.

And maybe get the stem(is that the name for it?) drawing to a separate function as well, but that's a matter of personal preference.

This career change seems like a really big step.
Hope you won't give up.
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Pursuing MSCS

Wow, thanks very much stranac!

This career change seems like a really big step.
Hope you won't give up.

Me too! Here I am, 55 years old (as of next week) and changing careers. The MS Computer Science degree I'm going to pursue is at a university where I'm already teaching part time (I have an MS in Post-Secondary Education). The CS dept. is probably going to require me to take five "transition" classes before taking the twelve courses for the MSCS degree - I am very much looking forward to these opportunities to build a reasonable foundation, preparing for the post-graduate level courses.

I'm planning on starting in January 2014 and taking four years to complete (51 hours total) while still working full time. That would toss me into the real world with an MSCS degree in December of 2017, if all goes to plan of course. At 59 years old, my career plan would involve professional practice for at least four or five years, then returning to the teaching profession, teaching CS courses and continuing with that until the day I die.

I'm excited while simultaneously a bit apprehensive about this. My wife tells me I can do it . . . we shall see.

So, here goes - thanks again for the comments & suggestions, very much appreciated.
When I'm in a difficult situation and there seems to be no possible solution, for some reason I always feel a little better, have a little more optimism when I remember the scene where George Jetson screams "Jane! Stop this crazy thing!"

millis

Posts: 9
Joined: Sun Oct 20, 2013 12:46 pm

### Re: Pursuing MSCS

So I really liked your script, and wanted to see if I could make it a bit better structured.

The first thing I noticed after taking a better look were globals: you use them all over the place.
Using globals is really not a good practice - it makes code harder to read and maintain.
If you need a lot of shared state across multiple functions, it's usually a good idea to use classes.

It also looked to me like you had plans to implement some rotation, different leaf sizes and similar, so I did that as well.
As for the math involved, I didn't change much.

Here's how my code ended up looking(if you want to leave this as an exercise for yourself, I won't mind if you don't read it).
It could probably be made better, but I'm pretty satisfied with it.
Code: Select all
`import randomimport turtleclass Leaf(object):    def __init__(self, startX, startY, leaf_size, rotation):        self.startX = startX        self.startY = startY        self.leaf_size = leaf_size        self.rotation = rotation    def draw(self):        self.draw_leaves()        self.draw_stem()    def draw_leaves(self):        angle = 302 + self.rotation        size_delta = 25        for i in range(7):            if i > 3:                # start making the leafs smaller                size_delta = -25            angle += 32            self.leaf_size += size_delta            turtle.penup()            turtle.goto(self.startX, self.startY)            turtle.pendown()            turtle.begin_fill()            turtle.setheading(angle)            turtle.circle(self.leaf_size, 40)            turtle.setheading(angle - 180)            turtle.circle(self.leaf_size, 40)            turtle.penup()            turtle.end_fill()    def draw_stem(self):        turtle.pendown()        turtle.begin_fill()        turtle.setheading(275 + self.rotation)        turtle.forward(leaf_size / 2)        turtle.setheading(180 + self.rotation)        turtle.forward(self.leaf_size / 10)        turtle.goto(self.startX, self.startY)        turtle.setheading(90 + self.rotation)        turtle.end_fill()        turtle.penup()turtle.speed(0)turtle.pen(fillcolor="#008844", pencolor="green", pensize=2)for i in range(33):    # I prefer to use randint when I don't need randrange's step parameter    startX = random.randint(-250, 250)    startY = random.randint(-250, 250)    leaf_size = random.randint(10, 200)    rotation = random.randint(0, 360)    Leaf(startX, startY, leaf_size, rotation).draw()`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Pursuing MSCS

stranac wrote:So I really liked your script, and wanted to see if I could make it a bit better structured.
I guess I'm making the obvious "newbie mistakes." Thank you for the suggestions.

stranac wrote:It could probably be made better, but I'm pretty satisfied with it.
The random rotations and sizing are great but I think it would be better if the missing two small bottom parts, next to the stem, were included. Where did they go?
When I'm in a difficult situation and there seems to be no possible solution, for some reason I always feel a little better, have a little more optimism when I remember the scene where George Jetson screams "Jane! Stop this crazy thing!"

millis

Posts: 9
Joined: Sun Oct 20, 2013 12:46 pm

### Re: Pursuing MSCS

Guess they went for a walk...
But now they're back.
Code: Select all
`import randomimport turtleclass Leaf(object):    def __init__(self, startX, startY, leaf_size, rotation):        self.startX = startX        self.startY = startY        self.leaf_size = leaf_size        self.rotation = rotation    def draw(self):        self.draw_leaves()        self.draw_stem()    def draw_leaves(self):        angle = 302 + self.rotation        size_delta = 25        for i in range(9):            turtle.penup()            turtle.goto(self.startX, self.startY)            turtle.pendown()            turtle.begin_fill()            turtle.setheading(angle)            turtle.circle(self.leaf_size, 40)            turtle.setheading(angle - 180)            turtle.circle(self.leaf_size, 40)            turtle.penup()            turtle.end_fill()            if i > 3:                # start making the leafs smaller                size_delta = -25            angle += 32            self.leaf_size += size_delta    def draw_stem(self):        turtle.pendown()        turtle.begin_fill()        turtle.setheading(275 + self.rotation)        turtle.forward(leaf_size / 2)        turtle.setheading(180 + self.rotation)        turtle.forward(self.leaf_size / 10)        turtle.goto(self.startX, self.startY)        turtle.setheading(90 + self.rotation)        turtle.end_fill()        turtle.penup()turtle.speed(0)turtle.pen(fillcolor="#008844", pencolor="green", pensize=2)for i in range(33):    # I prefer to use randint when I don't need randrange's step parameter    startX = random.randint(-250, 250)    startY = random.randint(-250, 250)    leaf_size = random.randint(10, 200)    rotation = random.randint(0, 360)    Leaf(startX, startY, leaf_size, rotation).draw()`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Pursuing MSCS

Thanks for fixing it.

Here's another script (?) I created yesterday - a very simple guessing game

Based on your comments earlier, I can see now that I should make some changes - but hey, it worked, and that was my goal

Code: Select all
`import randomauto_pick = random.randrange(1,101,1)user_pick = auto_pick + 1while user_pick != auto_pick:    user_pick = int(input("Enter a value from 1 to 100 "))    if user_pick == auto_pick:        print ("You win!")    else:        if user_pick < auto_pick:            print ("too low")        else:            print ("too high")`
When I'm in a difficult situation and there seems to be no possible solution, for some reason I always feel a little better, have a little more optimism when I remember the scene where George Jetson screams "Jane! Stop this crazy thing!"

millis

Posts: 9
Joined: Sun Oct 20, 2013 12:46 pm

### Re: Pursuing MSCS

This looks ok.
The only thing I would really do different is change the
Code: Select all
`ifelse    if    else`

into
Code: Select all
`ifelifelse`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Pursuing MSCS

I wrote this during lunch today . . . looks better when running in a large window . . .

Code: Select all
`"""    --> bw lunch stuff 01"""import randomdef skiing():    rNum = random.randrange(120)    for i in range(rNum):        print (" " * (80+i), "[|]")    for i in range(rNum):        print (" " * (rNum+80-i), "[|]")for i in range(2500):    skiing()`
When I'm in a difficult situation and there seems to be no possible solution, for some reason I always feel a little better, have a little more optimism when I remember the scene where George Jetson screams "Jane! Stop this crazy thing!"

millis

Posts: 9
Joined: Sun Oct 20, 2013 12:46 pm

### Re: Pursuing MSCS

. . . just a brief update: I'm no longer going to pursue an MSCS degree

After discussing this potential career change with three wildly different "professional programmers," I'm not convinced I would enjoy the daily coding grind although I would love to teach at the local university

For the remainder of my life, I'm sure I'll continue to enjoy programming at the hobbyist level

With the utmost respect and appreciation for "real programmers" thank you & best of luck with everything to all of you

You may find me here again someday
When I'm in a difficult situation and there seems to be no possible solution, for some reason I always feel a little better, have a little more optimism when I remember the scene where George Jetson screams "Jane! Stop this crazy thing!"

millis

Posts: 9
Joined: Sun Oct 20, 2013 12:46 pm