Re: [Tutor] What is wrong with my code?
On 01/23/2015 04:40 PM, Antonia van der Leeuw wrote: Hehey! I'm learning python on a website called codecademy.com, where I made a program to decode binary numbers. I guess the site uses a different compiler, because on the site my code worked fine, but when I copied and pasted it into the Python IDLE (3.4.2) it didn't work! When asking a question here, it's really more useful to say in what way it didn't work. Like if you crashed with an exception, show the stack trace including the error. Still, it's a pretty safe guess that you got an exception on the print statement(s), which is a function in Python 3.x. I'm really don't know what is wrong with my code, can anyone of you fine sirs help me? Meh code: number_input = input("What binary number do you want me to decode? ") def decoder(number): number_backwards = str(number)[::-1] # Because binary numbers go from right to left. result = 0 value = 1 br = False for n in number_backwards: if n != "1" and n != "0": print number, "is not a binary number" print(number, "is not a binary number") br = True break elif n == "1": result += value value += value if br == False: print "The binary number decoded is", result print("The binary number decoded is", result) decoder(number_input) -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is wrong with my code?
Danny Yoo writes: > Python 3 is a different language than Python 2. It looks like the > codeacademy materials use Python 2, so you should probably do the same > on your local system. Alternatively, learn Python 3 (which at this time means learning somewhere other than Codecademy). https://wiki.python.org/moin/BeginnersGuide/NonProgrammers> Python 2 is only ever going to be the past, don't learn it until you need to. Learning Python 3 is essential to keep your knowledge relevant today, and I strongly recommending learning Python 3 *first*. -- \ “The Vatican is not a state.… a state must have people. There | `\are no Vaticanians.… No-one gets born in the Vatican except by | _o__)an unfortunate accident.” —Geoffrey Robertson, 2010-09-18 | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is wrong with my code?
On Fri, Jan 23, 2015 at 1:40 PM, Antonia van der Leeuw wrote: > Hehey! > > I'm learning python on a website called codecademy.com, where I made a > program to decode binary numbers. I guess the site uses a different > compiler, because on the site my code worked fine, but when I copied and > pasted it into the Python IDLE (3.4.2) it didn't work! I'm really don't know > what is wrong with my code, can anyone of you fine sirs help me? Hi Antonia, Python 3 is a different language than Python 2. It looks like the codeacademy materials use Python 2, so you should probably do the same on your local system. By the way, next time you ask a question where something goes wrong, also show us what went wrong. Be descriptive! When you learn to program, you'll find that programs break for all sorts of crazy pedantic reasons. Normally, a Python program will explain *why* it broke. In your specific situation, it should have said something that points to one of the lines of your program, with a particular error message. When you see this and ask for help, copy and paste the error message. It will help. Good luck to you! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] What is wrong with my code?
Hehey! I'm learning python on a website called codecademy.com, where I made a program to decode binary numbers. I guess the site uses a different compiler, because on the site my code worked fine, but when I copied and pasted it into the Python IDLE (3.4.2) it didn't work! I'm really don't know what is wrong with my code, can anyone of you fine sirs help me? Meh code: number_input = input("What binary number do you want me to decode? ") def decoder(number): number_backwards = str(number)[::-1] # Because binary numbers go from right to left. result = 0 value = 1 br = False for n in number_backwards: if n != "1" and n != "0": print number, "is not a binary number" br = True break elif n == "1": result += value value += value if br == False: print "The binary number decoded is", result decoder(number_input) Thank you! ^^ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is wrong with my code?
On 10/25/2011 7:34 AM, Dave Angel wrote: (Once again, please don't top-post. It makes your responses out of order) On 10/25/2011 04:24 AM, apometron wrote: I did it very much times, Anssi. Beyond of run it on Python 2.7 latest build, what do you suggest? Do install Python 3.2 along the Python 2.7 installation could give me any problems? Why don't you say publicly that you aren't using cmd ? If your file manager is not running the equivalent of python yourprogram.py filename.txt then everyone here is chasing a wild goose. Switch to the command line, issue a sequence of commands that cause the failure, and paste them in a message here. Then if it works, but doesn't from your file manager, you/we/they can address the differences from the working command line. I found out what it is. It is the File Commander giving wrong informations to the script. In Take Command command line it works sweet. I will show all this to the File Commander author and ask him some way to solve this. It turns out do the thing in command line every time is not best way. I need do it by the file manager. But the file manager was puting stones in the way. Take Command has a script language also, but I would like do the things in Python, if possible. And this difficulty with File Commander makes use Python a thing less easy to do. Question solved. It was not Take Command the problem and I was sure it was not. Enter in command line to do things is a pain. =( I mean, e-ve-ry ti-me. But then, good news, all the three scripts works smoothly in the command line. Do you believe drag and drop in the Windows Explorer can be my salvation? Cool thing to try. []s Apometron http://about.me/apometron ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is wrong with my code?
(Once again, please don't top-post. It makes your responses out of order) On 10/25/2011 04:24 AM, apometron wrote: I did it very much times, Anssi. Beyond of run it on Python 2.7 latest build, what do you suggest? Do install Python 3.2 along the Python 2.7 installation could give me any problems? Why don't you say publicly that you aren't using cmd ? If your file manager is not running the equivalent of python yourprogram.py filename.txt then everyone here is chasing a wild goose. Switch to the command line, issue a sequence of commands that cause the failure, and paste them in a message here. Then if it works, but doesn't from your file manager, you/we/they can address the differences from the working command line. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is wrong with my code?
I did it very much times, Anssi. Beyond of run it on Python 2.7 latest build, what do you suggest? Do install Python 3.2 along the Python 2.7 installation could give me any problems? cheers, Apometron http://about.me/apometron On 10/25/2011 6:11 AM, Anssi Saari wrote: apometron writes: Now it is another thing, entirely. Rename1.py and Rename2.py works, but why Rename3.py dont works? Well, Rename3.py works for me, even in Windows 7. Maybe you should test it again? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is wrong with my code?
Sorry to continue discussing my thread on this list, I already subbed on the Tutor list but I need to reply and if possible, some ideas of why it dont works. Now it is another thing, entirely. Rename1.py and Rename2.py works, but why Rename3.py dont works? http://pastebin.com/dExFtTkp Thanks by the gentle support. []s Apometron On 10/23/2011 8:56 PM, Dave Angel wrote: On 10/23/2011 06:03 AM, apometron wrote: import os nome = sys.argv[1] final = nome for i in nome: print i if nome[i] = "_": final[i] = " " os.rename(nome, final) What do you want to be wrong with it? There are so many things, it'd be fun to try to see who could come up with the most. 1) it's not a valid Fortran program. 2) it's missing a shebang line if we assume it's for Windows, or that you run it with an explicit bash line 3) if we pretend it's a python program, a few more 3a) It has a syntax error calling the print() function. (Python 3.2) If we assume it's a python 2.x program 4) it uses sys, without importing it 5) it uses second argument without checking if the user typed such an argument 6) it tries to change a character within a string, which is a non-mutable type 7) It creates two more references to the same string sys.argv[1], then tries to modify one of them, not realizing the others would change to. 8) it tries to subscript a string using a character. 9) it calls rename with two references to the same object. So nothing will ever actually happen, even if the other problems were fixed. Generally, you'll get the best answers here if you specify more of your environment (python version, OS), show what you tried (pasted from the command line), and the results you got (such as stack traces). HTH DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor