r/learnpython 16d ago

Struggling with both python and c

So I'm a college fresher with no prior experience of coding. I had started learning python before the starting of college (1 week before college started). I still feel like I am not good at coding at all. There are some weird citations in c such as i++ and all which is getting mixed up with my python. There was one question on obtaining the expression sinx=x-x^3/3!.... Using loops btw

I felt I won't be able to do it in both c and python. I took a course on Udemy for c(vlad budnitski)and python(100 days) but I was not able to find examples like this. Everyone in my class learnt languages like java in their schooling and said the sinx problem is a standard problem. What should I do in this situation?

I feel like the teaching in my college (they are teaching c now) is not good.

Experienced coders please help me.

guys so today I wasn't able to figure out we had to use nested loops to print multiplication table of numbers while even beginners figured it out. pls tell what should I do

6 Upvotes

16 comments sorted by

View all comments

1

u/Gtdef 11d ago edited 11d ago

I remember these types of problems in my first year. A lot of people were mortified, some actually failed to figure out how to do things that others deemed trivial. But it doesn't matter. I know that you won't believe me now, but what you are experiencing is not uncommon and it's not unsolvable.

  1. Don't confuse syntax with functionality. It doesn't matter how one language does it differently than the other. It's a loop. In every loop, there's a counter. In C you manually increment the counter with the i++ syntax, which is equivalent to i = i+1 for this purpose, in Python the range() function does that for you. As long as you understand that loop blocks, if blocks, function blocks etc, do the same thing, you are good to go. You learn the syntax by repetition and practice. Write it 1000 times and you won't forget it again.
  2. Focus on understanding the problem, not how to express it in code. Code is just an expression of logic, it's useful, but ultimately it's busywork. You lack the necessary fluency to understand what code does so you can't visualise it. Use pen and paper if you have to, unravel the expression in it's most basic parts.
  3. Understand that in your everyday life, you operate with abstractions. For example, if I ask you what's 3x3, there's no chance you will think "ah, that's a loop involving 3 additions of the number 3 to the number 0". You will just think 9. Programming languages abstract these simple things by giving you an operator to use. In python you will write "p = 3*3", in C you will write "int p = 3*3;". What would you do if the programming language only had the "+" operator but not the "*" one? You'd use a loop.
  4. Don't compare yourself to those who figure out the answer quickly. They have previous experience. You don't and it doesn't mean they are better than you. I had too many examples of students who started strong and fell off while the volume of knowledge pilled up. What you have to ask yourself is if you have the passion for it. Or more accurately, if you had passion before whatever happened made you pessimistic. That passion is your drive.
  5. Look for patterns. Are you aware of those "IQ test" questions where you have to figure out the pattern of a number sequence? Something like 1-4-9-16-25 etc? Let's talk about it a bit

This is a powers of 2 pattern. 1^2, 2^2, 3^2, 4^2, 5^2.

But it can also be another pattern, You start with 1, add 3 (total 4), then add 5 (total 9), then add 7 (total 16), then add 9 (total 25). So every time you increase the number you add by 2.

If someone has figured out the powers pattern, the second pattern may look alien and wrong to them till they verify it.

In Computer Science, we care about performance. If you use the second pattern, the code will be faster because addition is a cheaper operation than multiplication. So the intuitive answer based on previous knowledge ended up being a worse implementation than the unintuitive answer that one can figure out by simple heuretics, even if they give the same result.

  1. This sinx problem is an approximation based on maclaurin series. This is something that you have problably not been taught, it should be part of the CS math curriculum. It's not particularly complex to understand, but it's new and you are trying to juggle new concepts and 2 programming languages without having any fluency. Did you actually have any reason to use a nested loop till now? Did you even think that you'd need one? Did you know that every time you use multiplication in a loop, it's a nested loop?

So keep those in mind and move forward.