> -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
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
o
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, ValueEr
This one worked! Thank you very much! :D
On Fri, Nov 21, 2014 at 3:14 AM, Adam Jensen wrote:
> On Thu, 20 Nov 2014 21:20:27 +
> Stephanie Morrow wrote:
>
> > Hi there,
> >
> > I have been posed with the following challenge:
> >
> > "Create a script that will ask for a number. Check if thei
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
wrote:
> On 20/11/14
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
On Thu, 20 Nov 2014 21:20:27 +
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 and print out the result."
>
> I was able to do
#!/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)
e
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
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 wrote:
> > I have been posed with the following challenge:
> >
> > "Cr
On Thu, Nov 20, 2014 at 3:05 PM, Stephanie Morrow 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 tangent but related,
> 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
12 matches
Mail list logo