Re: int vs. float

2017-02-11 Thread Steve D'Aprano
On Sun, 12 Feb 2017 02:34 pm, Chris Angelico wrote: > On Sun, Feb 12, 2017 at 2:27 PM, Steve D'Aprano > wrote: >>> >>> For example: >>> >>>>>> ast.literal_eval("( 1.0, 3 )").__class__.__name__ >>>'tuple' >> >> >> In what way does returning a tuple match the requirement "return an int >> o

Re: int vs. float

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 06:00 pm, Amit Yaron wrote: > Another option: > Use 'float' instead of 'int'. and check using the method 'is_integer' > of floating point numbers: > > >>> 3.5.is_integer() > False > >>> 4.0.is_integer() > True A bad option... py> float('12345678901234567') 1.234567890123

Re: int vs. float

2017-02-11 Thread Chris Angelico
On Sun, Feb 12, 2017 at 2:27 PM, Steve D'Aprano wrote: >> >> For example: >> >>>>> ast.literal_eval("( 1.0, 3 )").__class__.__name__ >>'tuple' > > > In what way does returning a tuple match the requirement "return an int or a > float or generate an error message"? Easy. You just use a ver

Re: int vs. float

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 07:24 pm, Marko Rauhamaa wrote: > boB Stepp : > >> According to the OP's professor's challenge, the OP needs to recognize >> an input of "4.0" as a float and "4" as an integer, and to respond >> with an error message in the float case, or "decimal number" case as >> the OP phr

Re: int vs. float

2017-02-11 Thread Erik
[Dan, this isn't "aimed" at you personally, it's just a follow-up on the general point I am (and I think you are also) making] On 11/02/17 02:17, Dan Sommers wrote: At least it works both ways: Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright"

Re: int vs. float

2017-02-11 Thread Amit Yaron
On 11/02/17 09:47, boB Stepp wrote: On Sat, Feb 11, 2017 at 1:00 AM, Amit Yaron wrote: On 10/02/17 21:15, Peter Pearson wrote: On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron wrote: On 10/02/17 04:33, adam14711...@gmail.com wrote: My computer programming professor challenged me to figure

Re: int vs. float

2017-02-11 Thread Marko Rauhamaa
boB Stepp : > According to the OP's professor's challenge, the OP needs to recognize > an input of "4.0" as a float and "4" as an integer, and to respond > with an error message in the float case, or "decimal number" case as > the OP phrased it. Apparently only positive integers are acceptable >

Re: int vs. float

2017-02-10 Thread boB Stepp
On Sat, Feb 11, 2017 at 1:00 AM, Amit Yaron wrote: > On 10/02/17 21:15, Peter Pearson wrote: >> >> On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron >> wrote: >>> >>> On 10/02/17 04:33, adam14711...@gmail.com wrote: My computer programming professor challenged me to figure out a way to ma

Re: int vs. float

2017-02-10 Thread Amit Yaron
On 10/02/17 21:15, Peter Pearson wrote: On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron wrote: On 10/02/17 04:33, adam14711...@gmail.com wrote: Hello, My computer programming professor challenged me to figure out a way to manipulate my program to display one error message if the user input is

Re: int vs. float

2017-02-10 Thread Dan Sommers
On Fri, 10 Feb 2017 20:46:16 +, Erik wrote: > Python 3.5.2 (default, Nov 17 2016, 17:05:23) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 0.5 > 1.0 > >>> f = float("0.5") > >>> i = int(f) > >>>

Re: int vs. float

2017-02-10 Thread Erik
On 10/02/17 19:15, Peter Pearson wrote: > On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron wrote: >> Use: >> >> try: >>num=int(str) >> except ValueError e: >>print "Error: not an integer" > > What should happen if the user types "1.0"? > > To be flexible about this possibility, you could

Re: int vs. float

2017-02-10 Thread Peter Pearson
On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron wrote: > On 10/02/17 04:33, adam14711...@gmail.com wrote: >> Hello, >> >> My computer programming professor challenged me to figure out a way >> to manipulate my program to display one error message if the user >> input is a zero or a negative number,

Re: int vs. float

2017-02-10 Thread Amit Yaron
On 10/02/17 04:33, adam14711...@gmail.com wrote: Hello, My computer programming professor challenged me to figure out a way to manipulate my program to display one error message if the user input is a zero or a negative number, and a separate error message if the user input is a decimal numbe

Re: int vs. float

2017-02-09 Thread Chris Angelico
On Fri, Feb 10, 2017 at 1:33 PM, wrote: > I understand that because I am starting out by assigning my > number_purchases_str to be an int, when the user enters a float that is a > conflict and will crash. > > My professor apparently believes there is a way to accomplish this. Any help > or ad

int vs. float

2017-02-09 Thread adam14711993
Hello, My computer programming professor challenged me to figure out a way to manipulate my program to display one error message if the user input is a zero or a negative number, and a separate error message if the user input is a decimal number. My program starts out: number_purchases_str =