Software Development and Programming Careers (Official Discussion Thread)

JahFocus CS

Get It How You Get It
Joined
Sep 10, 2014
Messages
20,462
Reputation
3,754
Daps
82,446
Reppin
Republic of New Afrika
Can someone explain to me why this code in Python:

for x in range(10):
if x % 2 == 0:
continue
print(x)

prints 1, 3, 5, 7, 9 ?

I originally read it as saying if x is divisible by 2, continue past (skip) the for condition. But it is actually saying, check is x is divisible by 2, and if it is, pass that batch and print the other numbers?

:whoa: I'm just starting out and this is my first time engaging with the continue function
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,292
Reputation
5,551
Daps
83,491
Can someone explain to me why this code in Python:



prints 1, 3, 5, 7, 9 ?

I originally read it as saying if x is divisible by 2, continue past (skip) the for condition. But it is actually saying, check is x is divisible by 2, and if it is, pass that batch and print the other numbers?

:whoa: I'm just starting out and this is my first time engaging with the continue function

Continue skips the current iteration and goes back to the loop and goes with the next iteration. essentially what is happening is you are iterating over a range. The % is the modulo operator and returns the remainder after a division. x % 2 == 0 is saying if x divided by 2 has a remainder of 0, then it evaluates to true. the continue keyword skips the current loop iteration and goes back to the top. In other words if x divided by 2 has a remainder of zero, skip the rest of this loop past the continue and go back to the top.
 

Neuromancer

Son of the Robot
Supporter
Joined
Oct 16, 2015
Messages
77,048
Reputation
14,817
Daps
185,581
Reppin
A Villa Straylight.
In my game I'm using a visually scripting language called Blueprints. Here is a screenshot of what the code looks like (not mine)

fetch


You could imagine this shyt is a nightmare for large, complex code. I've implemented alot of features that work as intended but the code is ugly as fukk. One of these days I'm gonna have to spend hours cleaning shyt up.
Looks kinda like block coding. Pretty cool.
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,706
Reputation
25,201
Daps
131,209
Can someone explain to me why this code in Python:



prints 1, 3, 5, 7, 9 ?

I originally read it as saying if x is divisible by 2, continue past (skip) the for condition. But it is actually saying, check is x is divisible by 2, and if it is, pass that batch and print the other numbers?

:whoa: I'm just starting out and this is my first time engaging with the continue function
Continuing from kevm3, in my experience you generally won't see the continue keyword used. The if statement will usually be written with x%2==1. Further to the point, don't use the goto keyword if Python has it because you create the spaghetti code effect. You should try as much as possible for a one entry, one exit rule for your functions. My first CS professor hit me with the
MMG4z.gif

For using them when we got to control flow.
 

Pyrexcup

Superstar
Joined
Dec 30, 2012
Messages
4,746
Reputation
765
Daps
14,814
Reppin
NULL
imma business computing student and having avoiding programming up untill now :francis: gonna have to up my programming skills and embrace it before i graduate seems like almost any type of job with good salary within IT/dev requires you to have good scripting or programming skills
 

MollyGalaga

+*++****+*+*+*=*++*.*+
Joined
Dec 30, 2014
Messages
8,077
Reputation
3,584
Daps
21,064
Reppin
HTX
Question for you guys in college/graduated or just people who learned how to program:

What tools did you guys use besides reading books?

I had a programming assignment due friday and i turned it in incomplete because for the life of me I could not figure out how to put the code together. :to:

Something like Chegg, but not like Chegg cause I used them before :shaq2:

then i have a test tomorrow:damn:
 

JahFocus CS

Get It How You Get It
Joined
Sep 10, 2014
Messages
20,462
Reputation
3,754
Daps
82,446
Reppin
Republic of New Afrika
In Python I ran this script and it didn't work:

def list_benefits():
return ["More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"]​

# Modify this function to concatenate to each benefit - " is a benefit of functions!"
def build_sentence(benefit):
return "{} is a benefit of functions!".format(list_benefits[0], list_benefits[1], list_benefits[2], list_benefits[3])​

def name_the_benefits_of_functions():
list_of_benefits = list_benefits()
for benefit in list_of_benefits:​
print(build_sentence(benefit))

name_the_benefits_of_functions()

The solution was:

def list_benefits():
return "More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"​

# Modify this function to concatenate to each benefit - " is a benefit of functions!"
def build_sentence(benefit):
return "%s is a benefit of functions!" % benefit​

def name_the_benefits_of_functions():
list_of_benefits = list_benefits()
for benefit in list_of_benefits:
print(build_sentence(benefit))​

name_the_benefits_of_functions()

Should I not have made list_benefits a list and should I avoid doing concatenation with string formatting methods as I did in the second part of code?

Also, I don't want to clutter up this thread with all of my questions if that is an issue, I'll start a Python Q&A thread if others are interested in that :lupe:
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,706
Reputation
25,201
Daps
131,209
Question for you guys in college/graduated or just people who learned how to program:

What tools did you guys use besides reading books?

I had a programming assignment due friday and i turned it in incomplete because for the life of me I could not figure out how to put the code together. :to:

Something like Chegg, but not like Chegg cause I used them before :shaq2:

then i have a test tomorrow:damn:
Practice honestly. When you run into roadblocks Google it or ask here.
 

wastedmermaid

Superstar
Joined
Sep 8, 2015
Messages
2,144
Reputation
230
Daps
13,853
Bout to start this java class on Monday. Already ran through most of the free classes on code academy this weekend. You breh got any tips or suggestions :lupe:
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,706
Reputation
25,201
Daps
131,209
Bout to start this java class on Monday. Already ran through most of the free classes on code academy this weekend. You breh got any tips or suggestions :lupe:
Programming is basically writing step by step instructions. As long as you can think sequentially you'll be fine. Pay attention, start assignments early and don't wait until a day or two before they're due and you'll be fine.
 

wastedmermaid

Superstar
Joined
Sep 8, 2015
Messages
2,144
Reputation
230
Daps
13,853
Programming is basically writing step by step instructions. As long as you can think sequentially you'll be fine. Pay attention, start assignments early and don't wait until a day or two before they're due and you'll be fine.
how many hours a day would you recommend practicing? outside of regular class assignments.
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,706
Reputation
25,201
Daps
131,209
how many hours a day would you recommend practicing? outside of regular class assignments.
I don't have an answer for that because I never really practiced programming. Usually your class assignments will be enough. The only way to properly practice is to work on projects but if you're coming into this with no prior knowledge then doing more work on the side can be overwhelming. Don't stress on it too much.
 
Top