Learn Python in 100 days thread

Secure Da Bag

Veteran
Joined
Dec 20, 2017
Messages
40,047
Reputation
20,339
Daps
126,183
So I finished day one and had a few questions about general good coding principles

1. She brought up the idea of nesting code, is this a good principle to adopt professionally?

For example:

Taking a non-nested program like this one, which tells you the number of characters in your name.

Ex: Bill = 4

-name = input (“What is your name?”)
-print(len(name))

VERSUS NESTING IT LIKE THIS (which she provides as an example)

print(len((input(“What is your name?))))

In terms of practicality and functionality, especially for future projects which is the better practice moving forward? Keeping the code elementary or trying to nest it?

2. This is a follow up that ties into the nesting question, but I am asking this to clear up some confusion.

So the function of this line of code is to create a new line for the input. Meaning that when the user has the option to input, it is on a new line, not the same one as the instructions.

Which is the better line of code (professionally)?

A:

- input(“What is your name? \n”)

OR

B:
- Print (“What is your name?”)
- input()

1. You'll find nested code all the time in professional code. Personally, I keep it unnested as much as possible. It's easier to read and debug.
2. Professionally, both are acceptable. In this specific case, better is subjective.
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,852
Reputation
25,252
Daps
131,941
So I finished day one and had a few questions about general good coding principles

1. She brought up the idea of nesting code, is this a good principle to adopt professionally?

For example:

Taking a non-nested program like this one, which tells you the number of characters in your name.

Ex: Bill = 4

-name = input (“What is your name?”)
-print(len(name))

VERSUS NESTING IT LIKE THIS (which she provides as an example)

print(len((input(“What is your name?))))

In terms of practicality and functionality, especially for future projects which is the better practice moving forward? Keeping the code elementary or trying to nest it?

2. This is a follow up that ties into the nesting question, but I am asking this to clear up some confusion.

So the function of this line of code is to create a new line for the input. Meaning that when the user has the option to input, it is on a new line, not the same one as the instructions.

Which is the better line of code (professionally)?

A:

- input(“What is your name? \n”)

OR

B:
- Print (“What is your name?”)
- input()
Readability is extremely important. While having
Code:
print(len((input(“What is your name?))))
Is valid, there's a lot going on in there too decipher. What if I gave you
Code:
print(len((input(“What is your name?)))))
Or
Code:
print(len((input(“What is your name?)))
How easy is it to spot the mistakes I introduced? I know you probably typed that on the fly, but you had a mistake anyway, no closing quote on the string literal. So even though it comes out to more lines of code, this is easier to parse visually when you're bug fixing and trying to look over your code again in 6-12 months.
Code:
name = input (“What is your name?”)
print(len(name))

In your second question, A is probably the better option because it's accepted that a call to input will print out the string you give it. Going with option B has you making an unnecessary call. If performance was a limitation, cutting down on method calls will give you a quicker execution time.



There's the computer science background on method calls.
 

Tr0yTV

All Star
Joined
Mar 20, 2017
Messages
1,235
Reputation
916
Daps
5,136
Good thread. Might use this as motivation to do 100 days straight of freecodecamp
 

Pete Wrigley

Twerk, Petunia, Twerk!
Supporter
Joined
May 1, 2012
Messages
5,579
Reputation
4,684
Daps
25,320
I feel like I'm the only person doing this. :mjcry:
I'm gonna hop on this week breh

I'm currently working on a freelance project and working on updating some code from jQuery to vanilla javascript.

I really want to brush up on my Python but keep going!
 

King

The black man is always targeted.
Joined
Apr 8, 2017
Messages
18,670
Reputation
4,029
Daps
79,620
Finished day 2

Got a in a bit of a hiccup because the math was unclear but I understand the underlying structure

Hoping to implement more f strings, they’re pretty convenient :ehh:
 

Mike809

Veteran
Supporter
Joined
Oct 15, 2015
Messages
16,101
Reputation
3,651
Daps
82,108
Reppin
Bronx
I been doing 2 lessons per day , so for example i just did day 5 and 6 today.
Mostly because i know the early stuff , and once i hit like day 19 is when ill dial it back.
 

xiceman191

Superstar
Joined
Jan 23, 2015
Messages
6,260
Reputation
2,328
Daps
29,826
I just finished Day 1. I already knew the basics of programming but I want to go through this day by day like the course is intended for.
 

HoldThisL

Captain L
Joined
Dec 7, 2014
Messages
13,529
Reputation
1,655
Daps
42,192
Im gonna hop on this after I finish my AWS course. I have been having trouble all year trying to complete courses because of my ADHD but finally found a way to learn better with it. Alnost finish and then gonna tackle on this.
 

gogogubari

Mjpls I'm already black
Supporter
Joined
Aug 7, 2015
Messages
3,558
Reputation
4,340
Daps
16,402
Reppin
YERDMEH
Just saw this thread and I reached out to one person in the PMs. I’m interested in this course for my kid (early teenager). Do you think it’s doable for a teen or should I start them off with something more basic? Has coded before through online classes but I am not knowledgeable enough to know if the work sucks or not.
 

Secure Da Bag

Veteran
Joined
Dec 20, 2017
Messages
40,047
Reputation
20,339
Daps
126,183
Just saw this thread and I reached out to one person in the PMs. I’m interested in this course for my kid (early teenager). Do you think it’s doable for a teen or should I start them off with something more basic? Has coded before through online classes but I am not knowledgeable enough to know if the work sucks or not.

This course will be good for him. The teacher is really good. It might take him more than a day to complete the exercise but that's to be expected.
 

gogogubari

Mjpls I'm already black
Supporter
Joined
Aug 7, 2015
Messages
3,558
Reputation
4,340
Daps
16,402
Reppin
YERDMEH
This course will be good for him. The teacher is really good. It might take him more than a day to complete the exercise but that's to be expected.

Thanks. I’m about to purchase the course now for a Christmas gift. Also, if you know any other things that would be good for a starter, just let me k ow. I’m open to all ideas.i want to prepare them for college.
 
Top