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
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
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
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
[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"
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
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
>
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
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
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)
> >>>
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
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,
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
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
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 =
15 matches
Mail list logo