For problem set 6 - sentimental, what are the exact specifications?

Explanation of the question:

While working on the first problems in this problem set, I made programs which could be checked with style50 foo.py and which could be run using python -m foo.

Later on, I noticed that the hints told us to run the programs using python foo.py. But I cannot see anything like that in the specifications ...

Does that mean that we have to test that our program can also work with python foo.py, or is it good enough if they can work with python -m foo?

Background: I happen to know that some programs do not work with python foo.py while they work perfectly when called from another program (or from the command line using python -m foo). Don't know whether than can also happen the other way round.

Additional question:

  • Are we supposed to port all our programs from C to python for this exercise? (in other words: learning how to port a program)
  • Or is it good enough if we write these programs in python from scratch? (in other words: learning to code in another language)

Off topic: After carefully reading that additional question, I've decided to port my credit.c program to python (and try to keep it readable). In my case, I think I can learn more that way (for this particular program). But that's just a personal decision, not quite related to the general question.

1 Answer 1


My submissions used the pattern

def main():
    #main function

def my_helper():
    #whatever else I'm doing

if __name__ == "__main__":
    #actually run the stuff, all functions are available

and passed the tests. Though I never tried with -m, they work in both ways.

I don't think -m makes much of a difference when you have a single file.

Additionally, I have added a shebang #! /usr/bin/env python3 and made them executable, which would probably call them just like python foo, but that was just for convenience and should be ignored by the checker.

I mostly ported my programmes so they would pass the tests, and then tried to incorporate Python's language features like list comprehensions while keeping my code working, often increasing readability. Since the programmes are quite basic, there shouldn't be much of a difference, porting might give you a better idea of equivalents, and you can still rewrite parts later.

  • Problem is: I like my python programs to be python. I've seen far too much programs which feel like Java or C++ programs coded with python syntax. So I will try to port some of the C programs to python programs which feel like python, not like C ...(I expect I'll switch back to python for the crack program) Commented Oct 5, 2018 at 17:52
  • It took quite a lot of time to port credit.c to python. I think I could have written it in Python 3 directly about times in that same time. I guess that means that I need to port some more of my programs, to build more experience ... Commented Oct 7, 2018 at 10:45
  • Especially string operations are so different in Python, where strings are immutable. So I am not at all surprised that this was slowest to port over.
    – Blauelf
    Commented Oct 7, 2018 at 11:08
  • Yeah, that might have had some influence. But I think the poor design of my C program also played an important role. As long as it is C, I can accept that the code looks ugly at some places. If it is C, I've always got the feeling that efficiency is somewhat more important (as long as the code is maintainable. But when it is python, I cannot accept that. Python was designed for programmers, so whenever it doesn't "feel" good, there's something wrong .. Commented Oct 7, 2018 at 11:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .