before. As you could tell there are also a shorter version to do this,
using list comprehension method. I would recommend you to use codeacademy
if you are not sure. Here is a quickest way for the ODD/EVEN list
comprehension. Both works the same way too.
Yes, I agree with Alan Gauld.
if you wanted to get your point across you should mention your
intention and could have posted any error message along with your code.
Because, your question is vague and if the original script of the code had
been posted, that would have been a huge help.
Is that any section of the function?? If it is then please, repost your
question with full definition of the function and please read python's rule
to indentation, maybe that's where the error is. However, as you said your
function execute normally, therefore I am assuming you misunderstood how
while loops works. Note for you: I don't think there would be any exception
raise for ValueError in your code so try: and except: method would not be
necessary..
"""ODD or EVEN Finder: """
X=input("Enter the number which you want to check for odd and even: ")
number=int(X)
print("The number ", number, " is Even.")
#number +=1
print("The number ",number, " is Odd")
break
pass
Post by Alan GauldPost by a***@yahoo.inHey guys can anybody tell me what's wrong with this code: The code is below?
Please in future
1) start a new thread with a new post, do not hijack somebody else's
query. It messes up the archive and threaded mail/newsreaders
2) Use plain text for posting code, your post is all messed up by the
mail system so we can't see the code clearly. It is all on one line...
Actually the point is that when we put "34h4" type of value
Post by a***@yahoo.init's an valueerror but here no handling is been performed
The handling only happens if it occurs inside a try block. It looks as
if your type conversion (int(...)) happens outside the try block.
The error is raised by the type conversion.
while 1: number=int(input("Enter the number which u want to check
Post by a***@yahoo.infor odd and even :")) try : if number%2==0: print("The
number",number ," is Even") else: print("The number
",number ," is Odd") except ValueError: print("Invalid
Input")
Finally, handling an error by simply printing a bland error message
is usually not a good idea. You effectively hide a lot of valuable
debugging information. You would be better to just let Python print
out its usual, much more helpful, error message.
(The exception is where it's the top level of an end-user program
where the Python trace might scare the users. But that should only
be after you have thoroughly debugged it and handled most of the
likely problem scenarios, and hopefully logged the error data
into a logfile or sent it as an email to your support desk.)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor