----BEGIN CLASS---- [13:27] #startclass [13:28] This is an informal session today, I am here to take questions on python, unit testing, etc. [13:28] rtnpro, roll call? [13:28] yes [13:28] #rollcall [13:28] Ashwani Kumar Gupta [13:29] Mohit Bansal [13:29] Bhavin Gandhi [13:30] Anu kumari Gupta [13:30] kumar vipin yadav [13:30] Onyinye Madubuko [13:31] cool [13:31] do you have any general questions with Python so far? [13:32] something you do not understand, etc? [13:32] ! [13:35] next [13:35] What is the difference between virtualenv and venv? [13:35] AFAIK, they are alias for each other venv == virtual env [13:35] ! [13:35] next [13:36] I am unable to use venv [13:36] anuGupta, what do you mean? [13:36] I am facing issues since last class on virtual environment [13:37] anuGupta, what issues? could you paste the error log somewhere? [13:37] Yes wait [13:40] https://paste.fedoraproject.org/paste/3G6e12ox2tD-IEBhIEfdXw [13:40] What might have caused this? I tried installing several things. [13:41] anuGupta, it says paste not found [13:43] https://paste.fedoraproject.org/paste/tCRgdhkqny1gKXqdwWQkvw [13:43] anuGupta, same here, "paste not found" [13:43] Hello friednds, is there eny session today. Sorry for being late [13:43] *friends [13:44] yurii, it's just an informal QA session going on right now [13:44] anuGupta, why don't you use the 'virtualenv' command directly? [13:45] rtnpro Thank you [13:45] anuGupta, just follow the docs here: https://virtualenv.pypa.io/en/stable/userguide/#usage and you will be good [13:47] Oh yes [13:47] Got it. Thanks rtnpro [13:47] cool [13:47] next [13:49] shall we try an exercise? [13:50] rtnpro, yes please [13:50] rtnpro, yes [13:50] cool [13:51] Sorry for being late , hi everyone [13:51] let's write a program to calculate the nth fibonacci number [13:52] can you quickly implement it and share your code, then we'll discuss on it [13:55] rtnpro, https://paste.fedoraproject.org/paste/h-jdMDw5Sh0YLfv8YGlpzQ [13:56] next, let's calculate the time it takes to run calculate the fibonacci [13:57] you can import 'time' and do start = time.time() before calculating the fibonacci number, and post that do, print(time.time() - start) [14:01] rtnpro, https://paste.fedoraproject.org/paste/cR1LRdBAUJNsqPtGJSL0BA [14:04] ashwanig, now try to alter the value of n, put higher values, 100, 10000, see how it fairs? [14:04] rtnpro, stack overflow [14:04] ashwanig, also, try to write an iterative solution for the same problem, and compare performances of both implementations for higher values of n and see what performs better [14:05] ashwanig, what value of n did you put? [14:05] where it err'd out? [14:05] rtnpro, 10000 [14:06] ashwanig, what about 1000? [14:06] rtnpro, even with 1000 it is same [14:07] ashwanig, what about 500 [14:07] rtnpro: mine is still computing with 100 [14:07] ashwanig, on azure notebooks it gives me answer for 100000 as well [14:07] rtnpro, same as schubisu [14:08] bhavin192, same code? or iterative version? [14:08] ashwanig, iterative version [14:08] here it is https://paste.fedoraproject.org/paste/vMaBDZT27LVtN-Ez6oy54A [14:08] in Python, there's something called a recursion limit [14:09] so, the interpreter prevents you from doing indefinite recursion [14:09] recursions are costly [14:09] ! [14:10] every time you recurse, there's a cost of doing a function call, the local variables of the calling function are dumped to stack [14:10] new local variables for the called function is created, etc [14:10] next [14:10] there is a formula mentioned https://paste.fedoraproject.org/paste/xOzuI1j4HVZlPsyBcwfPag/ [14:10] ! [14:11] so according to you it wont give complexity of o (logn) ? [14:11] if we use recursion [14:11] [14:11] by complexity i mean time complexity [14:12] sitlanigaurav[m], I have never spoken about complexity here [14:12] it will still give [14:13] time is not equal to complexity, it's proportional to it [14:13] there are various factors that go in there [14:13] rtnpro: So it will compute in less time as compared to sequential ? [14:13] sitlanigaurav[m], how? [14:14] i mean will it ? [14:14] please try to write an iterative version for it and try to examine [14:14] sure i'll compare both [14:14] cool [14:15] let the data speal [14:15] speak* [14:15] I'll share in a while [14:15] ashwanig, can you please run it on azure notebooks? [14:15] rtnpro, we will compare my code (iterative) and ashwanig's code [14:16] bhavin192, where's your code? [14:16] link? [14:16] ashwanig, are you done with the iterative implementation? [14:16] rtnpro, https://paste.fedoraproject.org/paste/vMaBDZT27LVtN-Ez6oy54A [14:17] everyone, don't depend on other's implementation, do your implementation yourself [14:17] rtnpro, yes wait [14:17] rtnpro, https://paste.fedoraproject.org/paste/duketOjyAI4HnHuROlv94A [14:18] now, measure the time consumed across the implementations [14:20] what's the runtime for n = 500 [14:24] rtnpro, tried for n = 30 [14:24] Iterative is 0.20639681816101074 sec faster [14:24] try for bigger numbers [14:24] 500 [14:24] for greater n value it is taking too much time :( [14:25] it will take [14:26] it will take time, but the iterative solution will return results for n > 1000 [14:26] lessons learnt... [14:26] rtnpro: yeah I'm getting a limit exceeded error with recursion [14:26] iterative solutions might not be as pretty as recursive ones, but they are faster [14:27] sitlanigaurav[m], try with iterative approach [14:27] lesson learned [14:27] it's because of the function calls happening [14:27] a function call has a cost [14:28] shall i share that error? [14:28] so, when you write big programs, it makes sense to break it into smaller functions, but don't overdo it [14:28] don't nest function calls too deep [14:28] else, it might slow things down [14:28] sitlanigaurav[m], not required [14:29] sitlanigaurav[m], you can google about the error and read about it [14:29] the objective is to keep things lean and simple [14:29] you will learn these by writing a lot of code, when you hit problems, and when you fix them [14:30] that's all from my side, for today ----END CLASS----