On Thu, 22 Sep 2016 11:40 pm, Sayth Renshaw wrote:
> True it failed, just actually happy to get it to fail or pass successfully
> on int input.
But it doesn't. It raises ValueError no matter what you enter.
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
e
On 09/22/2016 06:40 AM, Sayth Renshaw wrote:
[snip...]
True it failed, just actually happy to get it to fail or pass successfully on
int input.
Just felt it was a clearer and more consistent approach to verifying input,
then most of the varied and rather inconsistent approaches I have seen in
> > This ends being the code I can use to get it to work, seems clear and
> > pythonic, open to opinion on that :-)
>
> Neither clear, nor Pythonic.
Sadly imo clearer than the many hack attempts on SO.
>
> > answer = input("\t >> ")
>
> Since input() returns a string in Python 3, this will al
On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote:
answer = input("\t >> ")
if isinstance(int(answer), int) is True:
raise ValueError("Ints aren't valid input")
You seem to be trying to check that the user hasn't entered
an integer. But that's a backwards way of loo
On Thu, 22 Sep 2016 01:41 pm, Sayth Renshaw wrote:
> This ends being the code I can use to get it to work, seems clear and
> pythonic, open to opinion on that :-)
Neither clear, nor Pythonic.
> answer = input("\t >> ")
Since input() returns a string in Python 3, this will always be a string.
On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote:
> This ends being the code I can use to get it to work, seems clear and
> pythonic, open to opinion on that :-)
>
>
> answer = input("\t >> ")
> if isinstance(int(answer), int) is True:
> raise ValueError("Ints aren'
On Thursday, September 22, 2016 at 3:41:42 PM UTC+12, Sayth Renshaw wrote:
> if isinstance(int(answer), int) is True:
Not sure what the point of this is...
--
https://mail.python.org/mailman/listinfo/python-list
This ends being the code I can use to get it to work, seems clear and pythonic,
open to opinion on that :-)
answer = input("\t >> ")
if isinstance(int(answer), int) is True:
raise ValueError("Ints aren't valid input")
sys.exit()
elif isinstance(answer, str) is True:
print(v0 * t
To answer all the good replies.
I adapted a simple vector example from the Springer book practical primer on
science with python.
Having solved the actual problem I thought checking with the user they had the
correct entries or would like to ammend them would be a good addition. This
leads to
On Thu, 22 Sep 2016 12:26 am, Sayth Renshaw wrote:
> Hi
>
> Trying to clarify why ints and strings arent treated the same.
Because ints and strings are different? :-)
> You can get a valuerror from trying to cast a non-int to an int as in
> int(3.0) however you cannot do a non string with str(
In Sayth Renshaw
writes:
> Trying to clarify why ints and strings arent treated the same.
Because they are not the same.
> You can get a valuerror from trying to cast a non-int to an int as in
> int(3.0) however you cannot do a non string with str(a).
Anything you type can be represented as
On Wednesday, September 21, 2016 at 10:27:15 AM UTC-4, Sayth Renshaw wrote:
> Hi
>
> Trying to clarify why ints and strings arent treated the same.
>
> You can get a valuerror from trying to cast a non-int to an int as in
> int(3.0) however you cannot do a non string with str(a).
>
> Which mean
Hi
Trying to clarify why ints and strings arent treated the same.
You can get a valuerror from trying to cast a non-int to an int as in int(3.0)
however you cannot do a non string with str(a).
Which means that you likely should use try and except to test if a user enters
a non-int with valuerr
13 matches
Mail list logo