On December 27 2012 05:32 Perscienter wrote:
And please don't call functions in a print statement.
And please don't call functions in a print statement.
Why?
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
delHospital
Poland261 Posts
On December 27 2012 05:32 Perscienter wrote: And please don't call functions in a print statement. Why? | ||
Recognizable
Netherlands1552 Posts
On December 27 2012 05:45 Perscienter wrote: Use only lower case characters, underscores and numbers for function names. A style guide for Python can be found here: http://www.python.org/dev/peps/pep-0008/ It covers many aspects of formatting and how to name stuff. Calling is not renaming it. You define a function and you can call it. That's applying it. The code, which is included in your function is not applied until you call or apply the function. In your example, it would be done after the while loop, but can't reach the end of it, because n never reaches 100, since you don't call the function inside the while loop. It will become very clear to you, I have no doubt. Thank you. I figured it out. fibo = [1,2] Finally! I feel like such an idiot for not figuring that out on myself tho haha. But your explanation made it all very clear ![]() | ||
LunaSea
Luxembourg369 Posts
n = [1, 2] If you want to do it without a loop, a recursive function would also work :
The reason I added parenthesis around after the print method is because it changed from Python 2.7 to Python 3.x. | ||
Fwmeh
1286 Posts
| ||
Perscienter
957 Posts
On December 27 2012 05:49 delHospital wrote: Show nested quote + On December 27 2012 05:32 Perscienter wrote: And please don't call functions in a print statement. Why? Well, I take that back. I'm just not used to it. In the Python shell it wouldn't matter. But it only makes sense, when the function returns a value. So a generalized rejection of printing functions would be wrong. It does make sense, when functions return value and you want to print something, for instance in a console program. | ||
Recognizable
Netherlands1552 Posts
On December 27 2012 06:04 Fwmeh wrote: Now do it in time log(n) =P ? | ||
LunaSea
Luxembourg369 Posts
On December 27 2012 06:21 Recognizable wrote: ? He's referring to the "big O" notation and algorithm complexity calculations. Here is a pretty good post on the subject from Stackoverflow : --> http://stackoverflow.com/questions/487258/plain-english-explanation-of-big-o | ||
Shenghi
167 Posts
On December 27 2012 06:04 Fwmeh wrote: Now do it in time log(n) =P Why do it in O(log(n)) when there's a closed form formula to do it in O(1)? | ||
Fwmeh
1286 Posts
On December 27 2012 07:41 Shenghi wrote: Why do it in O(log(n)) when there's a closed form formula to do it in O(1)? 1) The closed formula will involve floats which are tricky 2) The closed formula will involve roots depending on the size, and roots are actually not in O(1), so the solution will not either 3) It is not very interesting to do it like that ^^ | ||
Shenghi
167 Posts
On December 27 2012 07:50 Fwmeh wrote: Show nested quote + On December 27 2012 07:41 Shenghi wrote: On December 27 2012 06:04 Fwmeh wrote: Now do it in time log(n) =P Why do it in O(log(n)) when there's a closed form formula to do it in O(1)? 1) The closed formula will involve floats which are tricky 2) The closed formula will involve roots depending on the size, and roots are actually not in O(1), so the solution will not either 3) It is not very interesting to do it like that ^^ 1) That's part of the challenge. 2) They are always the same roots (√5). 3) True. =] | ||
Fwmeh
1286 Posts
| ||
Shenghi
167 Posts
On December 27 2012 08:21 Fwmeh wrote: Well ok, you have to calculate (1+-√5)^n, and I don't think you can do that in constant time. I think I agree. If I recall correctly, the complexity of a^b is O(log(b)). | ||
Recognizable
Netherlands1552 Posts
Here is an example of such a list. O O O O O | ||
Zeke50100
United States2220 Posts
On December 29 2012 04:42 Recognizable wrote: If you have a 2 dimensional list in Python. Why does len(list) return the length of the row(x-coordinate) and len(list[0]) the length of the column(y-coordinate)? A 2 dimensional list is really just a list of lists. The first dimension specifies which list you wish to access, and the second dimension specifies the term in the list. Using "row" and "column" is somewhat misleading because rows and columns are just visual representations (and not actually what's happening under the hood). len(myList) will give you how many lists there are (in other words, the number of "rows") because myList is a list just like every other list - it just happens to be that the items in the list are lists themselves. Similarly, myList[0] will access list 0 stored in myList, and myList[1] will access list 1 in myList. len(myList[0]) will give you how many terms are in the list stored in myList[0] (or the number of "columns" in myList, if myList is rectangular - myList[0] can be a list of numbers, puppies, cookies, etc.). When you type in something like myList[0][1], you're saying "What is element 1 in the list, myList[0]?" | ||
Recognizable
Netherlands1552 Posts
![]() | ||
Abductedonut
United States324 Posts
One great kata is that of the bowling game kata, which can be found here: http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata There are several other katas on the internet that you can find - I just wanted to introduce the idea to you guys. Aside from katas, a lot of you come in asking for projects and things to practice programming on. CodeChef has a really great website for this. It splits up projects based on ranking (easy/medium/hard.. etc). As a bonus, there are monthly challenges, you can compare the memory usage and runtime of the programming languages used, and look at other peoples successful code. Link Here: http://www.codechef.com/ It's important to try and program every day to get good at it! Happy programming guys. And happy new year! | ||
Recognizable
Netherlands1552 Posts
On December 29 2012 17:43 Abductedonut wrote: Hello. I wanted to post something useful for those of you guys who are learning how to program. It is called a "Kata". A kata is basically an exercise that refines your programming skills. More importantly, when transitioning to a new language, you can program your katas in that language to get an understanding of how the program in that language. Rather than shifting through books re-learning the syntax, a kata will help you find the important aspects of that programming language. One great kata is that of the bowling game kata, which can be found here: http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata There are several other katas on the internet that you can find - I just wanted to introduce the idea to you guys. Aside from katas, a lot of you come in asking for projects and things to practice programming on. CodeChef has a really great website for this. It splits up projects based on ranking (easy/medium/hard.. etc). As a bonus, there are monthly challenges, you can compare the memory usage and runtime of the programming languages used, and look at other peoples successful code. Link Here: http://www.codechef.com/ It's important to try and program every day to get good at it! Happy programming guys. And happy new year! Thanks, I'll look into this. Almost finished LPTHW and Codeacademy, and I'm stuck on project euler problem 3 ![]() | ||
AmericanUmlaut
Germany2577 Posts
On December 30 2012 02:59 Recognizable wrote: Show nested quote + On December 29 2012 17:43 Abductedonut wrote: Hello. I wanted to post something useful for those of you guys who are learning how to program. It is called a "Kata". A kata is basically an exercise that refines your programming skills. More importantly, when transitioning to a new language, you can program your katas in that language to get an understanding of how the program in that language. Rather than shifting through books re-learning the syntax, a kata will help you find the important aspects of that programming language. One great kata is that of the bowling game kata, which can be found here: http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata There are several other katas on the internet that you can find - I just wanted to introduce the idea to you guys. Aside from katas, a lot of you come in asking for projects and things to practice programming on. CodeChef has a really great website for this. It splits up projects based on ranking (easy/medium/hard.. etc). As a bonus, there are monthly challenges, you can compare the memory usage and runtime of the programming languages used, and look at other peoples successful code. Link Here: http://www.codechef.com/ It's important to try and program every day to get good at it! Happy programming guys. And happy new year! Thanks, I'll look into this. Almost finished LPTHW and Codeacademy, and I'm stuck on project euler problem 3 ![]() That's the one where you need to get the largest prime factor of a really big number, right? Some suggestions to help you on your way: + Show Spoiler + 1. Depending on the language you're using, you'll probably need a library to store the number you're factoring. 2. Do you know how to get the prime factors of a number by hand? If so, you just need an algorithm that does the same thing, then you return the largest result. 3. Performance hint: Instead of performing division on a big number, you can determine whether a number is divisible by 2 by looking just at the last bit. | ||
Recognizable
Netherlands1552 Posts
| ||
windzor
Denmark1013 Posts
On December 30 2012 04:04 Recognizable wrote: Is a library the same thing as a list? Can't find it on google. In what context? My guess is, that in yours it's a no. | ||
| ||
![]() |
LiuLi Cup
Replay Cast
The PondCast
RSL Revival
Maru vs SHIN
MaNa vs MaxPax
Maestros of the Game
OSC
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
Reynor vs Astrea
Classic vs sOs
Maestros of the Game
BSL Team Wars
Team Bonyth vs Team Dewalt
CranKy Ducklings
[ Show More ] RSL Revival
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
Maestros of the Game
[BSL 2025] Weekly
RSL Revival
Cure vs Bunny
Creator vs Zoun
Maestros of the Game
BSL Team Wars
Team Hawk vs Team Sziky
Sparkling Tuna Cup
|
|