2 votes
Accepted

PSET6 CRACK (python)

Two things. First, and foremost, your program will keep going after it finds the password because your break only breaks out of the inner for loop. After finding the password, you should exit ...
user avatar
  • 18.4k
2 votes
Accepted

DNA doesn't work with large database

That code on StackOverflow is meant to calculate something else, I guess. We don't need overlap, in our case, we have to keep track of the longest contiguous repetition sequence. For that, we need ...
user avatar
  • 20.7k
1 vote

PS6 Lines Of Code :( lines.py yields 2058 given 2058 lines of code in an open-source library file

Any line in the input file that is all spaces will give an IndexError here in testLines function lines = [s for s in lines if s.lstrip()[0] != "#"] and will take the except branch and ...
user avatar
1 vote

CS50 PSET6 DNA problem. Need advices to make my code more pythonic

This isn't that long. Maybe consider using a dictionary for shtares as well. You don't really make good use of dictionaries here. You have several of these for x in range(len(keys)) type loops, which ...
user avatar
1 vote

PSET6 Mario Python

I think its because after your if argument, your return's indentation matches if's indentation. if and else should be consecutive and should not have anything other than argument between them. Try ...
user avatar
  • 361
1 vote

PSET6 Mario Python

Just like in C there were couple of bugs you have noted when you try to pair if and else and certain syntax error I think it makes the computer to extra think as it should not because obviously ...
user avatar
1 vote
Accepted

mario.py spacing issue

The i loop will print height + 1 lines. i starts at 0, so this "#" * i prints how many # on the first iteration?
user avatar
1 vote
Accepted

Stroring the header row from a csv file

header = next(<reader variable>) The next function should give you the 1st row of the file, but I am unsure if this is the answer to your situation as you did not provide any code.
user avatar
  • 711
1 vote
Accepted

pset6 Readability python: ugly code

Try .split() instead. And if you need to split multiple characters use regular expressions re.split() provided with characters given in specification for readability.c in pset2.
user avatar
1 vote

pset6 Readability python: ugly code

ugly's in the eyes of the beholder. What could be more explicit, more readable, simpler than that? There doesn't seem to be (read: I couldn't find) a python string method that will do it in one pass. ...
user avatar
1 vote
Accepted

PSET 6: Sentimental [Mario.py(less)]: How exactly do I "reject input" in Python as specified in check50?

Remember your C code. Reject in this case means to ask again. Use a loop around the input, and leave it on valid input (via loop condition or break). If the code were in a function, I'd raise an ...
user avatar
  • 20.7k
1 vote

greedy with Pyhton 3 - how to code the largest coins first with Python

You've converted the user entry into an integer representing the number of cents. But then, in your loops, you are using 0.25 (which, in this context means a quarter of a cent). Should that be 25 ...
user avatar
  • 18.4k
1 vote

mario pset6 PYTHON

while True: if Height > 1 or Height < 23: print("enter Height value between 1 and 23") break the right way is:EDIT (you are right) while True: print("enter Height value ...
user avatar
  • 5,172
1 vote
Accepted

Question about python dict syntax, how to past from one dict variable to another?

'share' a string variable that holds the values of an item in 'sharesOwned' so it is not a dictionary. If you took the square brackets away: share = shareNow['name'] This would allow the assignment. ...
user avatar
1 vote

How do I add a condition to a for() loop in Python?

You could use while and somewhat emulate for, or do an if with a break inside your loop (which I would prefer).
user avatar
  • 20.7k
1 vote
Accepted

Caesar.py (PSET 6) ValueError: invalid literal for int() with base 10

The message is telling you that 'h' cannot be changed to an int. True enough. From the Hints section of the spec: You might find chr and/or ord of help. I think chr is what you want, not int.
user avatar
1 vote

pset6 - greedy doesn't print answer- just returns the input. Where have I gone wrong?

if n >= 0: break This breaks you out of the While loop, so your program simply ends if the user gives you a positive number.
user avatar
  • 18.4k
1 vote
Accepted

pset6 (python) caesar prints capital letters and shifts non-alpha chars

isalpha and isupper are built-in methods that return a boolean. Therefore, the correct notation is isalpha() and isupper(). To get "eyes on", you can call interactive python at the command line and ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible