Software Development and Programming Careers (Official Discussion Thread)

OSUBaneBrowns

Ohio to California
Supporter
Joined
May 10, 2012
Messages
5,948
Reputation
823
Daps
16,091
Reppin
Long Beach, CA
can you share some examples here?

Here is a example of a question that I had a issue with before I was able to find the answer.

Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.

has_33([1, 3, 3]) → True
has_33([1, 3, 1, 3]) → False
has_33([3, 1, 3]) → False

Code:
def has_33(nums):
    for i in range(0,len(nums)-1):
        if nums[i] == 3 and nums[i+1] == 3:
            return True
    else:
        return False

I understand using the if/else statements, having the value ==3 and the true/false booleans. I think my issue is that I still not grasping the concept of the for loops and putting the pieces together to get the code to work.
 

Matt504

YSL as a gang must end
Joined
Sep 7, 2013
Messages
45,221
Reputation
14,767
Daps
274,008
Here is a example of a question that I had a issue with before I was able to find the answer.

Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.

has_33([1, 3, 3]) → True
has_33([1, 3, 1, 3]) → False
has_33([3, 1, 3]) → False

Code:
def has_33(nums):
    for i in range(0,len(nums)-1):
        if nums[i] == 3 and nums[i+1] == 3:
            return True
    else:
        return False

I understand using the if/else statements, having the value ==3 and the true/false booleans. I think my issue is that I still not grasping the concept of the for loops and putting the pieces together to get the code to work.


when you're using a for loop to iterate over a list of items, you're doing something to one at a time until you've checked the entire list. in the case of determining whether there are consecutive 3's in a list we start with a random list. let's take the first example. [1, 3, 3]

in our for loop, each i represents the index value of the list, if the list contains three values, the indices are 0, 1, 2 which maps to 1, 3, 3 in our list example.
on the first pass of the loop i = 0 we get the list value with bracket notation list is equal to 1. now that we have the first value we want to check two things:
  1. Is the value equal to 3
  2. Is the value after it also equal to 3
in the first loop list is equal to 1 so it doesn't make sense to check what the next value is yet as it's not equal to 3 and we'll find out on the next loop.
in the second loop list is equal to 3 so our first condition has been met we want to check what the next value is and we can do this by adding i+1
list[i+1] = 3, we want to return true because both conditions have been met.

Rpr1ZPJ.jpg
 
Last edited:

OSUBaneBrowns

Ohio to California
Supporter
Joined
May 10, 2012
Messages
5,948
Reputation
823
Daps
16,091
Reppin
Long Beach, CA
Everybody and their grandmom trying to be a programmer lol. It's going to be oversaturated like nursing and onlyfans thotology.
Nursing is a high demand job because not everyone is built to deal with old and sickly people. That why they get paid a lot of money because shyt is stressful and people get burnt out by it and leave.

The reason why I want to go into programming is because I want a career change. I have experience with reporting and working with clients so doing a transition to a business or reporting analyst would make sense since I already have a extensive banking background. There are a boat load of companies that needs programmers for their everyday business needs not just the big tech companies like Google, Amazon, Apple, etc. Plus there are a lot of old heads in every office who are working just for a paycheck and don't want to learn new shyt. You just can't just depend on outsourcing to India to fix everything, sometimes you need people in house to handle it for you on the spot.
 

OSUBaneBrowns

Ohio to California
Supporter
Joined
May 10, 2012
Messages
5,948
Reputation
823
Daps
16,091
Reppin
Long Beach, CA
when you're using a for loop to iterate over a list of items, you're doing something to one at a time until you've checked the entire list. in the case of determining whether there are consecutive 3's in a list we start with a random list. let's take the first example. [1, 3, 3]

in our for loop, each i represents the index value of the list, if the list contains three values, the indices are 0, 1, 2 which maps to 1, 3, 3 in our list example.
on the first pass of the loop i = 0 we get the list value with bracket notation list is equal to 1. now that we have the first value we want to check two things:
  1. Is the value equal to 3
  2. Is the value after it also equal to 3
in the first loop list is equal to 1 so it doesn't make sense to check what the next value is yet as it's not equal to 3 and we'll find out on the next loop.
in the second loop list is equal to 3 so our first condition has been met we want to check what the next value is and we can do this by adding i+1
list[i+1] = 3, we want to return true because both conditions have been met.

Rpr1ZPJ.jpg
Your explanation made more sense. I may need to go back on certain topics to make sure that I understand them. Thanks for the help.
 

patscorpio

It's a movement
Staff member
Supporter
Joined
Apr 30, 2012
Messages
119,882
Reputation
11,545
Daps
248,222
Reppin
MA/CT/Nigeria #byrdgang #RingGangRadio
Everybody and their grandmom trying to be a programmer lol. It's going to be oversaturated like nursing and onlyfans thotology.
nah..my lady is a nurse....when she had static at the hospital she was working full time at, she was able to find a new gig quickly...and stay on at the old hospital as per diem
 
Top