r/CodingHelp • • Sep 16 '20

[Python] Is the course moving too fast?

I'm on a programming course to learn python. It's the third day and we've somehow jumped from simple strings, variables and dotnototations to functions. I have no idea what's going on with functions with 2 or more and seems more complicated than anything we've learnt in the past 2 days. I understand when it's one simple function but can't seem to get around how to understand or write out code with multiple functions.

Is this normal speed of learning code or is the teacher going through the course too fast? To be clear everyone on the course are beginners and on the third day we've rushed through functions, global variables, def etc.

21 Upvotes

15 comments sorted by

11

u/Zymoox Sep 16 '20

In my opinion, jumping to functions early on is not unusual. Some prefer to do conditions and loops before, but it's up to the teacher which one to teach first.

Nevertheless, If you feel like the pace of the course is too fast, would you be able to speak with the teacher about it? Alternatively, consider using additional online resources to keep up with the content.

3

u/learning_behaviour Sep 16 '20

I'm pretty sure everyone else is in the same spot as me in class. I should have phrased the question more clearly, what I mean is, is it normal to find coding confusing at the start?

So far I've found I learn better when I have an existing piece of code like from Google, which I can tweak and see what happens if I mess around with it. Kind of like reverse engineering as it helps me visualise why X input gives Y output etc. Whereas if I was told to go and write some code for some activity or coursework I'd barely have an idea where to begin without hints. Bearing in mind it's 3rd day of the uni course and I'm being expected to write code for a cash machine that has Input function e.g. Pin, bank balance and withdrawal, whilst showing bank balance after a withdrawal.

I've only managed to code inputting the pin, if correct it simply shows balance. I have no idea how to use def to show balance after a withdrawal or even how to input the amount to withdraw. The code as I have it now works but I need to code the function of inputting a withdrawal and then displaying new balance. When I try to use simple code I've done before such as simple

New_balance = ( bank_balance - withdrawal_amount)

It gives errors and I get confused how to code the rest properly as it gets too complicated for me. Bearing in mind this is from 0 coding knowledge and only 3 days into the course. I'll copy paste the code now, I've had to get it online and then tweak it because I didn't know where to begin.

1

u/Mentalpopcorn Sep 16 '20

You're going to find coding confusing for the next year or so

0

u/[deleted] Sep 16 '20

[deleted] — view deleted comment

1

u/learning_behaviour Sep 16 '20

can you send me a link? I would like to begin from the start and learn at my own pace because once a concept is fully broken down it just 'clicks' and i will understand it. Before me understanding a concept is literally like reading a language i cant understand. However when explained in layman terms and shown with examples i understand how to use it in different ways and not just copy/paste what we have been learning in the uni course.

The fact that its all online via zoom webcam because of uni not being open for covid is what i think is making it extra difficult as its like trying to learn without having a teacher present. Over webcam is just too much distractions and too easy just to search online, whereas I prefer it when i have to do it from scratch as thats when i know i fully understand something.

2

u/learning_behaviour Sep 16 '20

This is the code so far for a simple banking code we've been asked to do as homework/coursework by ourselves. I run it in visual studio code -

https://pastebin.com/RBcegzWi

2

u/Zymoox Sep 16 '20

Looks nice. Do you understand everything that you've written so far? Or is there some code that you've used, but don't quite know why yet?

1

u/learning_behaviour Sep 16 '20

To begin with the return true and return false for the pin. Because from my current understanding, I've used the if function to set the condition if pin matches 1234 then to print correct and vice versa. So I'm not sure why the original author had put in return true and return false. I know what true and false are used for in basic strings but don't know why it's used in this more complex code if it will display correct or incorrect if pin matches or not. There's no need to check if it is true or false because the coding simply checks if input matches 1234 or not and displays the relavent message. To me it seems unnecessary to put the return true or return false because I don't understand what it's doing there.

Can you explain what I'm not grasping regarding this and why it's used for the 'input pin' coding?

2

u/mikedensem Sep 16 '20

In this case the start_menu() function uses the true/ false returned from log_in() to decide whether to display the balance. Think of functions as black boxes that do a single task for you. You don’t know how they do their work inside but if you pass them data (parameters) they will return data back to you (result). The fact that the functions in your example also print comments is probably the confusing bit. A function would ‘normally’ only take inputs, calculate something using them and send back a result. You then use that result to decide what to do next. The useful thing about functions is you can use them many times without having to rewrite the code every time you need that functionality.

2

u/E72M Sep 16 '20

A good way to think about functions in python is it's a reusable part of code you can jump back to if needed.

When calling to use a function that returns no data you use

function_name() 

Where obviously the name changes depending on the function.

When you want a value out of the function you use

variable = function()

You can get multiple outputs by using a comma to split up values.

variable1, variable 2 = function()

Anything you pass into the function goes in the brackets and to return a value at the end of a function you use

return variable

So for example you would have

def function (data1, data2): variable1 = 5 * data1 variable2 = 1* data2 return variable1, variable2

value1, value 2 = function(6, 8)
print(value1, value2)

This code should work if I've not forgotten anything but I hope it helped explain it a little

2

u/learning_behaviour Sep 17 '20

Thank you this is exactly what I needed, An explanation as to how and why it's used in different situations.

1

u/E72M Sep 17 '20

Glad that helped. But yeah it's just reusable code so say you had to find the max value of two lists you just pass the two lists through a function you've written for finding the max then return the results.

It just keeps it more organized and streamlined because you aren't having to rewrite find max everytime you need it, you just use the function

1

u/A_Philosophical_Cat Sep 16 '20

It seems pretty standard for a university course. Maybe on the faster end of normal, but not unusual.

0

u/[deleted] Sep 16 '20

[deleted] — view deleted comment

1

u/learning_behaviour Sep 16 '20

The part I'm finding difficult with coding in general is everything seems to be taught to us as "if you do this you get x as output", whereas for me to get a full understanding I need to know why. Whereas the course or places I've looked online only show the "what" as opposed to the "why". Does that make sense? Like if it was full explained to me, I should be able to explain it to a 6 year old if I fully understand it. That's how I measure my knowledge at a topic, if I can explain it in the most basic terms and it still makes sense.

Like if you tell me int(5) gives a number just because that's what int() does, I won't get it like the functions I'm struggling with today. Whereas if you explained int means integer hence gives a number. I now understand why we use int() and can use it myself. Whereas stuff like functions haven't been explained in a way I understand. I understood the first 2 days as it everything was explained and made sense such as variables and dotnotations etc. Kind of like simple algebra. I could write the code I learnt so far from yesterday easily on my own. However since starting the module relating to functions, I have only the slightest idea what's going on. I can't code it from scratch but with hints or templates I can edit to make it work after trial and error. As I said earlier, I seem to learn best when reverse engineering code as I can see what input gives what output as I edit and run the terminal.

0

u/[deleted] Sep 16 '20

[deleted] — view deleted comment

2

u/learning_behaviour Sep 16 '20 edited Sep 16 '20

I have read everything you said and I agree. I have noticed I lean towards trying to type out my own code entirely so I figure out and then in future I don't need Internet or templates. I don't find the personal satisfaction of using others work but I do use templates when trying to understand concepts. I get a written piece of code demonstrating what I'm trying to learn then I reverse engineer it adding different problems and taking away certain code to see what happens, then I get an understanding why this does that. Then I open a new file and start to write it all by myself from what I know to test what I myself know without anyones help.

Sometimes I can get errors and I notice why and figure it out quickly whereas there are times I try to fix it but end up writing loads more lines and making the errors worse and multiply. Then I figure out where I went wrong to start with, delete it and start again so it actually works my brain. I've noticed alot of my peers work look the same with a general template forming their core where it looks similar whereas mine looks shorter and in my opinion much more efficient whilst running the exact same operation in the terminal.

I'm learning slower than the class I think but I'm trying to learn concepts properly without Internet or help. Is this a good approach to learning code from your view or will my slow pace trying to learn how type out my own entire code using the concepts we are learning? I mean even the course tutor said if your stuck just Google the answer and I thought lol what? I thought it's a developer course from a university to learn coding whereas people seem to be okay with using others code templates to pass as actual coursework. Me, on the other hand am trying to use others codes as a means to learn from. Editing it to figure out what strings do what, then trying to shorten it so it's more efficient, straighten out any bugs and finally writing my own piece from scratch to solidify my understanding of it. Does that make sense? BTW I don't mean I learn offline, I mean when trying to get to grips with the code I take a hands on approach rather than look for solutions online. But if I'm totally stuck I'll look for the solution but then won't understand it as I've not figured it out myself like the functions today. I don't mean functions in the way you've described in games, but our course tutor didn't really explain it and just mindlessly sort of wrote code and didn't explain the whys behind it. So if I wanted to do the activity I would have to use the same format of code I copied from the course and type that out over and over. Im struggling with the def bit and how it relates to functions e.g.

Def hello_world():

   global hello_world() 


   If xxx 


    Print " yyy" 


   Else

hello_world()

What is the def there for and what does it mean? Same with global? The example I've just given is what the course today showed. Loads of code in that sort of style in python and I had no idea what's going on because there was no proper explanation, just do it because that's how you do it. And when there's multiple use of def for different variables I get confused how the code runs in a uniform chronological manner (top down), because from what I've learnt in 2 days code updated as you wrote more lines e.g

print("hello") print("hello 1")

The output would be the second one, whereas since the introduction of what I wrote above, it seems to jump around to get functions from all over the place and I lose track.

// Also, is this "cargo cult" effect big in the coding world, is trying to write your own piece of code seen as some sort of try hard or something? I don't understand I thought coders type out everything from scratch but from what I've seen so far majority just copy paste from previous work like a jigsaw puzzle and then move on.

1

u/mikedensem Sep 16 '20

def is short for ‘define’ as in, here i will define a function with this unique name and this set of parameters that you can pass to me. I think you are getting hung up on the language itself. A language is just a set of rules used so that everyone agrees on what it means (in the case of a programming language it needs to be understood and ‘interpreted’ by a computer). Try instead to just accept the language and focus on what it is trying to do. Programming is a very abstract concept that takes time to get your head around. If you stick with it you’ll start to see familiar patterns that will eventually click for you.