Re: [Tutor] Dividing a float derived from a string

2014-11-21 Thread Stephanie Morrow
Alan, I am getting a syntax error when I print the following: input = raw_input(Insert a number: ) try: print float(input) * 12 except: TypeError, ValueError: print False The try is coming up as red. Any idea why? On Fri, Nov 21, 2014 at 12:23 AM, Alan Gauld alan.ga...@btinternet.com

Re: [Tutor] Dividing a float derived from a string

2014-11-21 Thread Stephanie Morrow
This one worked! Thank you very much! :D On Fri, Nov 21, 2014 at 3:14 AM, Adam Jensen han...@riseup.net wrote: On Thu, 20 Nov 2014 21:20:27 + Stephanie Morrow svmor...@gmail.com wrote: Hi there, I have been posed with the following challenge: Create a script that will ask for a

Re: [Tutor] Dividing a float derived from a string

2014-11-21 Thread Alan Gauld
On 21/11/14 13:19, Stephanie Morrow wrote: try: print float(input) * 12 except: TypeError, ValueError: print False The try is coming up as red. Any idea why? Sorry, I left the colon in after the else. I think that's what's confusing it... It should read: except TypeError,

Re: [Tutor] Dividing a float derived from a string

2014-11-21 Thread Peter Otten
Alan Gauld wrote: But that's considered bad practice, it's better to put the valid errors only in the except line like this: try: print float(input)*12 except TypeError, ValueError: print False Careful, you need parens around the tuple of errors, otherwise this catches only

Re: [Tutor] Dividing a float derived from a string

2014-11-21 Thread Adam Jensen
-Original Message- From: Tutor [mailto:tutor-bounces+hanzer=riseup@python.org] On Behalf Of Alan Gauld Sent: Thursday, November 20, 2014 7:24 PM But that's considered bad practice, it's better to put the valid errors only in the except line like this: try: print

[Tutor] Dividing a float derived from a string

2014-11-20 Thread Stephanie Morrow
Hi there, I have been posed with the following challenge: Create a script that will ask for a number. Check if their input is a legitimate number. If it is, multiply it by 12 and print out the result. I was able to do this with the following code: input = raw_input(Insert a number: ) if

Re: [Tutor] Dividing a float derived from a string

2014-11-20 Thread Danny Yoo
I have been posed with the following challenge: Create a script that will ask for a number. Check if their input is a legitimate number. If it is, multiply it by 12 and print out the result. I was able to do this with the following code: input = raw_input(Insert a number: ) if

Re: [Tutor] Dividing a float derived from a string

2014-11-20 Thread Danny Yoo
On Thu, Nov 20, 2014 at 3:05 PM, Stephanie Morrow svmor...@gmail.com wrote: What else could I do in that testing portion that would allow for a decimal point? In order for a decimal to be True, it would have to accept both the digits and the decimal point. Let's tackle a problem that's

Re: [Tutor] Dividing a float derived from a string

2014-11-20 Thread Stephanie Morrow
What else could I do in that testing portion that would allow for a decimal point? In order for a decimal to be True, it would have to accept both the digits and the decimal point. On Thu, Nov 20, 2014 at 10:36 PM, Danny Yoo d...@hashcollision.org wrote: I have been posed with the following

Re: [Tutor] Dividing a float derived from a string

2014-11-20 Thread Alan Gauld
On 20/11/14 21:20, Stephanie Morrow wrote: input = raw_input(Insert a number: ) if input.isdigit(): print int(input) * 12 else: print False /However/, a colleague of mine pointed out that a decimal will return as False. As such, we have tried numerous methods to allow it to divide

Re: [Tutor] Dividing a float derived from a string

2014-11-20 Thread Adam Jensen
#!/usr/bin/env python3.4 good = False s = input('Enter a number: ') a = s.split('.') n = len(a) if n = 2: for y in a: if y.isdigit(): good = True else: good = False exit else: good = False if good: num = float(s) print(num * 12)

Re: [Tutor] Dividing a float derived from a string

2014-11-20 Thread Adam Jensen
On Thu, 20 Nov 2014 21:20:27 + Stephanie Morrow svmor...@gmail.com wrote: Hi there, I have been posed with the following challenge: Create a script that will ask for a number. Check if their input is a legitimate number. If it is, multiply it by 12 and print out the result. I was

Re: [Tutor] Dividing a float derived from a string

2014-11-20 Thread Steven D'Aprano
My response is interleaved with yours, below. On Thu, Nov 20, 2014 at 09:20:27PM +, Stephanie Morrow wrote: Hi there, I have been posed with the following challenge: Create a script that will ask for a number. Check if their input is a legitimate number. If it is, multiply it by 12