Discussion:
[Tutor] FW: query
Gupta, Manaswini Kat
2015-06-23 17:13:51 UTC
Permalink
From: Gupta, Manaswini Kat
Sent: Tuesday, June 23, 2015 10:42 PM
To: 'tutor-***@python.org'
Subject: FW: query



From: Gupta, Manaswini Kat
Sent: Tuesday, June 23, 2015 10:40 PM
To: 'tutor-***@python.org'
Subject: query

Hi,
I need to fetch the records of count(*)>3 can you please tell me the logic in python

Thanks&Regards,
Manaswini Gupta
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Emile van Sebille
2015-06-23 17:57:30 UTC
Permalink
You're more likely to get an appropriate response if you review
http://catb.org/~esr/faqs/smart-questions.html and then ask.

Emile
Post by Gupta, Manaswini Kat
From: Gupta, Manaswini Kat
Sent: Tuesday, June 23, 2015 10:42 PM
Subject: FW: query
From: Gupta, Manaswini Kat
Sent: Tuesday, June 23, 2015 10:40 PM
Subject: query
Hi,
I need to fetch the records of count(*)>3 can you please tell me the logic in python
Thanks&Regards,
Manaswini Gupta
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-06-23 18:01:58 UTC
Permalink
Post by Gupta, Manaswini Kat
I need to fetch the records of count(*)>3 can you please tell me the logic in python
Sorry, but that's not very clear.
What do you mean?

It looks like a bit of SQL so, are you asking how to execute
that SQL from within Python? If so on what database?

Or are you trying to convert SQL logic into pure Python code?
If so that depends on how you are storing your records.
Are they in a list, a dictionary, a flat file?

Also count(*)>3 is a boolean expression so it will
return True or False and no records.
What do you mean by fetching the records?
Which records?

You probably need to show us an example of your data and
the results you want. Maybe show us the full SQL query
you are trying to execute or emulate.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
a***@yahoo.in
2015-06-24 12:58:53 UTC
Permalink
Hey guys can anybody tell me what's wrong with this code: The code is below?Actually the point is that when we put "34h4" type of value it's an valueerror but here no handling is been performed by the python ???
while 1:    number=int(input("Enter the number which u want to check for 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")
Post by Gupta, Manaswini Kat
I need to fetch the records of count(*)>3 can you please tell me the logic in python
Sorry, but that's not very clear.
What do you mean?

It looks like a bit of SQL so, are you asking how to execute
that SQL from within Python? If so on what database?

Or are you trying to convert SQL logic into pure Python code?
If so that depends on how you are storing your records.
Are they in a list, a dictionary, a flat file?

Also count(*)>3 is a boolean expression so it will
return True or False and no records.
What do you mean by fetching the records?
Which records?

You probably need to show us an example of your data and
the results you want. Maybe show us the full SQL query
you are trying to execute or emulate.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail
Emile van Sebille
2015-06-24 16:15:05 UTC
Permalink
Post by a***@yahoo.in
Hey guys can anybody tell me what's wrong with this code: The code is below?
Actually the point is that when we put "34h4" type of value it's an valueerror
but here no handling is been performed by the python ???
number=int(input("Enter the number which u want to check for odd and even :"))
You're probably seeing the error here, which is outside your try/except
block, hence the except not working as you expect.
Emile



_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-06-24 16:27:36 UTC
Permalink
Post by a***@yahoo.in
Hey 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...
Post by a***@yahoo.in
Actually the point is that when we put "34h4" type of value
it'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.
Post by a***@yahoo.in
while 1: number=int(input("Enter the number which u want to check for 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
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Whom Isac
2015-06-25 04:06:43 UTC
Permalink
For ***@yahoo.in:
I had posted few solution to your question before but unfortunately they
were sent to Alan Gauld mail because I am not used to the ***@python.org
mail system.
Here is the code that will work:
""ODD/EVEN finder:"""


def odd_or_even():
X=input("Enter the number which you want to check for odd and even: ")
try:
number=int(X)
print("The number %s is ODD."%(number)if number%2!=0 else "The
number %s is EVEN."%(number))
except ValueError:
print("Invalid input")
X=input("Enter the number which you want to check for odd and even: ")
number=int(X)
print("The number %s is ODD."%(number) *if *number%2!=0 *else *"The
number %s is EVEN."%(number))
there is four or five ways to do your question as I had done one for you
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.
X=input("Enter the number which you want to check for odd and even: ")
number=int(X)
print("The %s is ODD"%(number)if number%2!=0 else "The %s is EVEN"%(number))
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 Gauld
Post by a***@yahoo.in
Hey 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.in
it'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.in
for 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
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Whom Isac
2015-06-25 04:08:09 UTC
Permalink
Sorry, the interpreter uses colour which is why some code is missing. Here
is the text version of my code:


def odd_or_even():
X=input("Enter the number which you want to check for odd and even: ")
try:
number=int(X)
print("The number %s is ODD."%(number)if number%2!=0 else "The
number %s is EVEN."%(number))
except ValueError:
print("Invalid input")
Post by Whom Isac
I had posted few solution to your question before but unfortunately they
mail system.
""ODD/EVEN finder:"""
X=input("Enter the number which you want to check for odd and even: ")
number=int(X)
print("The number %s is ODD."%(number)if number%2!=0 else "The number %s is EVEN."%(number))
print("Invalid input")
Post by Whom Isac
X=input("Enter the number which you want to check for odd and even: ")
number=int(X)
print("The number %s is ODD."%(number) *if *number%2!=0 *else *"The
number %s is EVEN."%(number))
there is four or five ways to do your question as I had done one for you
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.
X=input("Enter the number which you want to check for odd and even: ")
number=int(X)
print("The %s is ODD"%(number)if number%2!=0 else "The %s is EVEN"%(number))
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 Gauld
Post by a***@yahoo.in
Hey 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.in
it'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.in
for 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
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Continue reading on narkive:
Loading...