Don't use list as variable name. What is m, it is not defined before use at line 2?
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
Ug. How did you manage to get rid of the line numbers and code coloring? Use the [CODE] button next time, please.
There are a lot of problems, but lets start with just three:What you show can't even be running: It would stop with a problem on the second line: print m So I expect you didn't paste all your code...
You should be using raw_input(thePrompt) not input(thePrompt)
You should not use a list named 'list': It is confusing to both readers and sometimes to the Python interpreter ('list' is a built in type and a conversion function). Name it 'myList' or something more descriptive.
The general rule for new programmers (and wise old ones, too) is to write a very small program that works, then gradually modify it so it does what you want. Start with this program
myList = [['A', 'B', 'A'],['C', 'D', 'B']]
print(myList)
Then add a loop:
myList = [['A', 'B', 'A'],['C', 'D', 'B']]
while True:
user_input = raw_input("Type 'Q' to quit ")
if user_input.upper().startswith('Q'):
break
print(myList)
And continue making small changes, testing that your program still works, and improving until you are satisfied (or the deadline arrives)
griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
because of strange last line and not try except handling. Start small and add functionality with one step and test also it is good to prepare testing material in advance and run the tests after each change (unittest).
Print the values in your program for debugging!
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
Of course the code sample doesn't do what you want. But it runs and does what you would expect from reading it. Your code, on the other hand also doesn't do what you want, and it isn't obvious what it does from reading it. I'm suggesting that you start with something thatIs simple enough to understand easily
Doesn't do what you want
Can be "mutated" toward what you want
And then mutate it until it does do what you want.
Does your code run? If not, what is the exact error you get (please cut and paste it)... bet before you do that, look at it closely, read what it is saying and try to figure out what it means by that. This is an important skill to learn, and you have to actually think hard sometimes to get it.
If it does run, then what is the problem with how it runs? Say what you wanted to see and what you did see. And think hard about what could be causing it to act that way. Put a print statement somewhere (or several places) so when the program passes through that spot in your code you can see it happening on the screen.
Programming is (among other things) making your understanding of the problem so precise that you can describe how to solve it to an idiot savant that always does exactly what you tell it to do. (or complains that it doesn't understand what you tried to say: A syntax error). You need to be able to state things clearly to yourself at least. If you can do that, it is not so hard to make a clear statement to other people.
I don't understand what your stated problem is: The English language description was confusing to me. I don't understand what you are 'complaining' about your code: Your 'complaint' is not specific enough.
Tony and I have both made the suggestion that you start small and grow the program. Please think about why that seems the wrong thing to you... when two experienced programmers are both saying it is the right thing.
I pointed to three issues (and Tony mentioned two of the same). You have changed your code to partly (there is a remaining 'list' on the last line) fix two of the issues... with one change: Good! But you need to address the rest, too.
griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
I suggest you leave griswolf's code for later and do those three exercises on functions that you had not time to do (yourself).
Then complete this before you start the current assignment:
for number in ('a','b','1','','234234', '-234','4','-1'):
if check(number):
if in_correct_range(int(number), low, high):
print('Good! You gave right size of number')
else:
print('The number you gave was outside the limits')
else:
print('That was not number')
Here is missing two functions you should define, fixed values for range check. Write those. After that change this loop to while, which only exits the loop when correct input is given. Then put everything in function that returns that correct value out from function as integer.
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852