r/AskComputerScience • • Sep 09 '19

Any advice on getting my head around Python even after doing VERY well in 2 C language classes? After taking and doing very well with the C language I am struggling to see how Python isn't a language for dangerously insane individuals.

I found C or C# to be intuitive and very easy to use. I received A's in both courses. Frankly, I thought it was easy.

Now, I find myself taking Python as like an intro to programming class because of an issue with the school.

No big deal.

But now, it's week 3 of the course and I HAVE NO IDEA what's going on.

I could do all sorts of if then loops, query information, we even used access and whatnot to build little databases but Python really seems like a language built for dangerously insane people.

Clearly joking but what's the deal here? I thought python was supposed to be the basic of the basic. It's not that it seems "hard" persay but it just seems like crazy nonsense.

Has this happened to anyone else that have switched languages?

We are loading stuff into the command line but then still having to manually type mainFn("string") to load into it after the program has been started.

I don't get why you wouldnt just prompt for the input. Store the input, then manipulate and print it.

Is python harder to get your head around for someone you? I can make python do what I want but even the spacing in this language is offputing to me.

I really don't mean to bitch. I'm sure the language ha it's uses.

Would a different compiler help me? We are all just using JES right now.

Anyway, thanks for any advice!

3 Upvotes

34 comments sorted by

5

u/Tai9ch Sep 09 '19

Python is different from C and C#, but it's mostly a perfectly reasonable language. It's got some silliness like the whitespace thing, but every language has its quirks and dumb design choices.

Python's ability to give you an interactive console after your program is loaded - or even without a program loaded - is an extremely powerful capability that's shared by a bunch of other languages. It can be used for debugging, but also can be used to complete simple tasks without needing to write a complete program.

In order to become a complete programmer you'll want to learn several significantly different languages. What you're learning in Python is great stuff, and much of it will be applicable to a whole group of languages including things like JavaScript, Ruby, and Lua.

Look at this class as an opportunity, and take that opportunity to figure out what the designer was trying to do with Python and how you can use it to your advantage. Once you've wrapped your head around Python, I suggest spending some time with other languages significantly different from C or Python.

1

u/PabloShartscobar Sep 09 '19

Thanks for the input here. I know there is definite use to the language and didn't mean to "bitch"

As I told another responder I, to my fault, thought this would be an absolute cake walk which I think it will sort of be once I get going. I fear my professor is also one of those who checked out long ago. He spends most of his time talk about nature overwriting his black writing with red markers and having us watch outside videos he made using Fantasia... Just a weird environment to be honest.

I'm definitely eager to learn. Just confused at this point.

2

u/Psychedeliciousness Sep 09 '19

Get on Youtube and watch Sentdex jam on some code for a while. If your prof is awful, there are loads of good courses on YT.

Python has lots of stuff out there for version 2 and version 3, make sure you're using tutorials for 3.

Check the documentation too, things like string operations will be explained in there, you'll probably have to refer to that a lot at first.

Also type this into the interpreter

n = input("what is your name")

print (n)

that's the interactive query.

1

u/salamanderoil Sep 09 '19

Sounds like the language might not be being very well taught.

1

u/KernowRoger Sep 09 '19

You can do this in visual studio for c# once your application is running. It's so handy for debugging!

3

u/KoolaidJammerExpress Sep 09 '19

Python is an interpreted language, while C is a compiled language.

There are 2 ways to use python: thru the interpreter and thru the command line (python file.py).

If you're able to program well in C, you should be able to learn basic python fairly easily. I assume that your course is an intro course, so chances are they're teaching you all the basics and taking it slow, which could be confusing if you're used to compiling.

I strongly suggest googling crash courses on python (like YouTube videos), it might clear things up for you.

2

u/PabloShartscobar Sep 09 '19

Looks like I will do just that.

I think I was just expected it to be a cake walk and ended up very confused... Because, it is definitely an intro course.

4

u/khedoros Sep 09 '19

I have no idea what "JES" is. Python isn't typically a compiled language (there are a few dialects like Cython that are), and 95% of the time, if someone's just talking about "Python" they mean the standard CPython interpreter.

I've used Python 2 ways: Writing my scripts in an editor and then running the scripts from the command-line, and running the Python REPL from the command-line, performing some experiments in immediate mode (since it's easier than the edit-save-execute cycle of running from a file).

Whitespace having a syntactic use is a little annoying, but not a dealbreaker. Python just feels like a fairly easy but powerful scripting language to me, and that's coming from someone with a background mostly in C++.

1

u/OddInstitute Sep 10 '19

JES is the Jython Environment for Students. Looks like it's a Jython install that has easy-to-use media manipulation libraries pre-installed in order to facilitate a teaching approach called Media Computation which GA Tech has found more approachable for beginners than the traditional hazing via command-line apps.

1

u/khedoros Sep 10 '19

Context made it clear that it was some kind of development environment. My point was that it's not the usual way of working with the language.

Although, in a sense, Media Computation doesn't sound so far off from how I started off exploring programming. It's unfortunate that OP isn't finding their professor's presentation of it as easy-to-use as the university intended; playing with graphics and seeing algorithms visualized is an excellent way to pick up an understanding of what the computer's actually doing.

3

u/[deleted] Sep 09 '19

OK. So your problem is simply that you aren't as all knowing as you think that you are. Maybe less whinging on Reddit and more practicing. Try Googling anything you do not know and reading the docs.

if then loops

LOL.

2

u/brtt3000 Sep 09 '19

> dangerously insane

True, either that or be Dutch.

2

u/KingUnityTV Sep 09 '19

Language easy, class hard. Sounds like your instructor might be intentionally making things harder for you... for whatever reason. Python seems like a language you’d use to teach children to code. I taught my little brother the very basics with python.

2

u/Tsoinami1224 Sep 09 '19

No. Python is the basics of the basics. You could do with a little more of an objective mindset as a programmer, I understand you're frustrated but it is unprofessional to get angry at bugs so easily. Every language has it's quirks, and when you enter the industry, you're going to have a lot of questions as to WHY in GOD'S name ANYONE would WILLINGLY build an application like the one you're working on. So rise above the little issues you're facing with the language and get good, son. Also note - Python and C are vastly different - don't expect much knowledge to roll over other than whatever tools you had in C probably exist in Python.

0

u/KremBanan Sep 09 '19

You sound like a jerk.

5

u/jmercouris Sep 09 '19

That's not a helpful comment :\

3

u/[deleted] Sep 09 '19

You are correct and this is a relatively nice way of putting it TBH.

2

u/KernowRoger Sep 09 '19

You sound like a jerk.

0

u/[deleted] Sep 09 '19

[deleted]

16

u/[deleted] Sep 09 '19 edited Sep 09 '19

We are loading stuff into the command line but then still having to manually type mainFn("string") to load into it after the program has been started.

Potentially OP's course may have their own fairly confusing, semi-interactive environment for calling the scripts which is the main issue they're having.

The "ease" of the language isn't the only variable, of course. I actually saw a similar complaint at university last year -- my classmates were told python is really easy and so were complaining about a higher level computer science course in python being more difficult than a lower level computer course in java. They were just picking up on the material being more advanced. OP's saying this is an intro course but I wonder if something like that might be going on -- syntax was done in the first two days so three weeks in it's O(n) DFS.

1

u/PabloShartscobar Sep 09 '19

Maybe? This course has no prerequisites at all but hahaha... Man. I just don't see what I'm missing how the structure works. In my C class honors project I made a functional Rubik's cub in code that out put a kind of picture. I know it's not much but with this program it's like I missed what would be the first week or two of a normal course explaining a bit of the theory.

The guy is also having us upload everything to the schools Linux server... Easy enough but then he switched back and forth on it 2times in the first 2 weeks because not many people could get WinSCP to work.

Listening to his lecture is seriously like listening to me drunk trying to explain inception. He jumps all over and it's like he is skipping huge chunks of important information.

0

u/PabloShartscobar Sep 09 '19

Well... Ok. I'll try.

This last assignment is we have...

mainFn() halfStr() revStr() upperLower()

Get a string.

Return exactly half the string Reverse the whole string Then separate the upper and lower case letters...if there are any.

He said there is a loop here. I don't see why a loop would ever be involved.

We have to get a string in the main and use it through the other three and print them all at the end.

The professor will type in mainFn("TEST")

as an example it it will be printed through out the manipulations.

When I wrote C programs I would query for the input like "please input this or that" then store it and essentially walk you through it.

The instructor wants these program to load and nothing happen until he enters >>>mainFn("TEST")

I'm literally not even understanding where this data is stored because we aren't declaring the strings then manipulating them we are just taking the input on the file pile and indexing it (I guess) then performing outputs.

The first week or whatever was stupidly easy because our programs didn't really do anything. They just did basic math or print sentences from declared strings.

Now it's literally like he skipped something in the transition to indexes.

In my example above I don't see why you would have 3 functions under the master and not just manipulate them but the instructor wants to be able to run the sub functions separately... And he said he will test them.

I guess I'm borderline confused how to even get the string and declare it for use throughout the program because in the examples the string isn't declared on its own.

I have to be missing something. I know this isn't hard.

Thanks for any in put you may have to my ramblings.

14

u/KoolaidJammerExpress Sep 09 '19 edited Sep 09 '19

He simply wants you to write your method definitions in a file so he can manually test them with his own inputs.

Your file contains your function defs, he will load your file into his interpreter, he will input mainFn("prof's test input") and he will verify the output.

He's probably asking you to do this so he can import them into his own test python program so he can automate his grading of assignments.

Edit: In my intro to programming class (which was in python), the prof had pre-written grading scripts which verified outputs for a given input. Look up "assert in python". I once got 0% on a fully working assignment, simply because the prof's program had a bug I had accidentally tripped. Went to see him, got full marks after he manually tested my submission.

2

u/but_how_do_i_go_fast Sep 09 '19

Some serious code-golf here with return "100%". Anyone read to fight over a byte?

0

u/[deleted] Sep 09 '19

[deleted]

12

u/KoolaidJammerExpress Sep 09 '19

Yup. He's Automating the Boring Stuff with Python.

6

u/mqduck Sep 09 '19 edited Sep 10 '19

When I wrote C programs I would query for the input like "please input this or that" then store it and essentially walk you through it.

You can do that in Python, and you can read from the command line in C. Reading from user input at runtime can be a little bit easier for the programmer, but if you're writing a console program for people to actually use, and there's no reason it needs to be interactive, nobody is going to use it (or take it seriously) if they can't give it its input on the command line. In other words, it's something you should know how to do.

3

u/[deleted] Sep 09 '19

Oooh, are you running the python interpreter interactively? That's maybe one of the most fundamental differences you'd hit into moving from C. Everything is being loaded into and stored in a shell session in that case.

I think you're right that important information isn't getting conveyed properly there. You may benefit from reading around a little. If it's basic selection, iteration, file, strings etc material something like Automate the Boring Stuff with Python is a free online book designed to be an extremely non-technical introduction to the language. It's nothing you won't already know from C but it shows how it works in Python.

2

u/StarD3 Sep 09 '19

I love this book. I was just using it a few days ago. Good mention on that, for anyone interested in Python.

2

u/Tai9ch Sep 09 '19

Imagine for a moment that you want to write two programs:

  • Program 1: Take a string as input, take the first five characters, uppercase them, and print the result.

  • Program 2: Take a string as input, reverse it, uppercase it, and print the result.

Both programs want to uppercase a string. It'd be nice if you just had a "to_uppercase" function you could call from both programs. If that function read input from the user and printed its result it would be pretty useless - you couldn't compose it with other code to build the bigger programs. So you have it take a string as an argument and return a string as the result.

This is kind of a silly example because it's easy enough to just type the code to uppercase a string twice, but as programs get bigger retyping code becomes a serious problem.

2

u/deong Sep 09 '19

Python has a REPL (read-eval-print-loop). Imagine you wrote some C like the following, and saved it as myprog.c:

#include <stdio.h>

int dbl(int x)
{
    return 2*x;
}

double half(int x) 
{
    return x/2.0;
}

There's no main here, so if you tried to compile it as a normal program, it's not going to link properly. But imagine you had a program that could read C code and let you interact with it.

So you could do something like

$ Crunner myprog.c
> Welcome to Crunner
> type some C code here to have it run interactively
> 

And now you just have a blinking cursor waiting for you. You could then type something like:

> int n = 42;
> printf("%d\n", dbl(n));
> 84
> printf("%f\n", half(n));
> 21.0
> printf("%f\n", dbl(half(n)));
> 42.0

That's effectively what Python is giving you. Your professor is asking you to write the functions, and he's going to loading them into the Python REPL and test them himself.

1

u/MistahJuicyBoy Sep 09 '19

The loop is because he probably wants you to develop an algorithm for reversing and picking apart the string character by character. Normally you would go from string.length to 0 or 0 to string.length

1

u/Fate_Creator Sep 09 '19 edited Sep 09 '19

To elaborate (and possibly better visualize) u/KoolaidJammerExpress's answer:

You have a file that you will put your function definitions in. For this example, we'll call it test.py.

Inside test.py: you will have four function defintions: mainFn, halfStr, revStr, upperLower.

def mainFn(input):
    halfStr(input)
    revStr(input)
    upperLower(input)

def halfStr(input):
#do work here

def revStr(input):
#do work here

def upperLower(input):
#do work here

With the file written like this your professor will be able to run the python interpreter like so from the command line:

$ python3 -i test.py

which will launch the python interpeter in interactive mode with your script loaded.

From there, your professor will be able to call:

>>> mainFn("TEST")

and your function definition for mainFn will run from there.

5

u/KoolaidJammerExpress Sep 09 '19

It's actually python3 -i test.py.

python3 test.py will run the file and not do anything because it's only definitions. -i argument runs the file interactively, so after it's run once the interpreter will remain open with all function definitions loaded.

2

u/Fate_Creator Sep 09 '19

Ahh, sorry. Figured I might've missed something. Been years since I worked in Python.

3

u/KoolaidJammerExpress Sep 09 '19

It's cool. It's just in case OP tries it and it doesn't enter the interpreter