On Thu, Mar 26, 2015 at 5:42 PM, Priya Persaud wrote:
> Hello,
>
> I recently learned about if statements and math functions. For my class we
> are unit testing absolute values and have to make if statements so the
> tests pass, but we cannot use built in functions like (abs). How do I start
> it,
On 14/09/14 09:00, ALAN GAULD wrote:
So, to IDLE, your code looks like
if x < 0:
print(...)
elif x == 0:
Web mail screwed things up. That should be:
> if x < 0:
>print(...)
> elif x == 0:
To fix it you need to make it look like this on screen:
if x < 0:
n Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
>
> From: Gregory Donaldson
>To: Alan Gauld
>Sent: Sunday, 14 September 2014, 4:28
>Subject: Re: [Tutor] If statement The Python
On 06/09/14 00:29, Gregory Donaldson wrote:
This is what it looks like when I try to get it to work.
x = int(input("Please enter an integer: "))
Please enter an integer: 42
if x < 0:
x = 0
print('Negative changed to zero')
I'm guessing that you actually indented the two lines
above bu
On Fri, Sep 5, 2014 at 7:29 PM, Gregory Donaldson wrote:
> I've tried to copy this example from the Tutorial into the Python Idle, but
> it doesn't seem to recognize it.
>
> 4.1. if Statements¶
>
> Perhaps the most well-known statement type is the if statement. For example:
>
>
x = int(i
On 04/08/2013 07:55 AM, Steven D'Aprano wrote:
On 08/04/13 20:45, Dave Angel wrote:
will always fail, since the integer 2 is not equal to the type int.
In Python 2.x, when you compare objects of different types, you
generally get unequal. (Exception, if you define your own classes,
you can def
On 08/04/13 20:21, Max Smith wrote:
Hi, everyone whom might read this, im Max and i am really new to coding,
been going at it for about two weeks using codeacademy and the book "think
python".
when i decided to experiment a little with if statements i ran into the
following problem:
def plus(x,y
On 08/04/13 20:45, Dave Angel wrote:
will always fail, since the integer 2 is not equal to the type int. In Python
2.x, when you compare objects of different types, you generally get unequal.
(Exception, if you define your own classes, you can define how they compare to
others) In Python 3
On 04/08/2013 06:37 AM, Woody 544 wrote:
Max,
You've made the arguments a string (so never a number) in:
print "The answer is: " + str(x+y)
MJ
That has nothing to do with the issue. The str() function call is
unnecessary, but harmless. If the two values x and y are ints or
floats, they w
On 04/08/2013 06:21 AM, Max Smith wrote:
Hi, everyone whom might read this, im Max and i am really new to coding,
been going at it for about two weeks using codeacademy and the book "think
python".
when i decided to experiment a little with if statements i ran into the
following problem:
def plu
Max,
You've made the arguments a string (so never a number) in:
print "The answer is: " + str(x+y)
MJ
On Apr 8, 2013 6:23 AM, "Max Smith" wrote:
> Hi, everyone whom might read this, im Max and i am really new to coding,
> been going at it for about two weeks using codeacademy and the book "thi
Thanks for the explanation - very clear.
Cheers,
Bodsda
Sent from my BlackBerry® wireless device
-Original Message-
From: Steven D'Aprano
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Fri, 16 Sep 2011 20:43:45
To: Tutor - python List
Subject: Re: [Tutor] If stat
bod...@googlemail.com wrote:
Hi,
In a normal if,elif,elif,...,else statement, are the conditions checked in a
linear fashion?
Yes.
I am wondering if I should be making an effort to put the most likely true
condition at the beginning of the block
Probably not. The amount of time used in
Sorry, jumping in on this thread a couple days late...
Steven's suggestion is how I figured out a similar problem recently. If you're
executing the code through a windows command line, you might be getting the
carriage-return character returned to the program (this behavior doesn't happen
in I
Matthew Brunt wrote:
i'm very new to python (currently going through a python for beginners
book at work to pass the time), and i'm having trouble with an if
statement exercise. basically, i'm creating a very simple password
program that displays "Access Granted" if the if statement is true.
the
"Andre Engels" wrote
Actually, no, this case it's not your ignorance. What is probably
going on is that you are using Python 2, but the book is going with
Python 3.
You can quickly check the version by just typing python at
an OS command prompt to get into the interactive interpreter(>>>)
On Tue, Jun 7, 2011 at 11:26 PM, Matthew Brunt wrote:
> i'm very new to python (currently going through a python for beginners
> book at work to pass the time), and i'm having trouble with an if
> statement exercise. basically, i'm creating a very simple password
> program that displays "Access G
On 02/11/2010 20.07, Glen Clark wrote:
sorry:
NumItems = int(input("How many Items: "))
Entries = []
for In in range(0,NumItems):
Entries.append("")
for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))
for In in range(0,NumItems):
print
"Glen Clark" wrote
On a side note.. I didn't know you could do something like this:
x = z if
Yes it's python's equivalent to the C style
foo = testVal() ? bar : baz
Also found in other languages (Java, Javascript, Perl?)
Alan G.
___
Tu
> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Glen Clark
> Sent: Tuesday, November 02, 2010 3:07 PM
> To: python mail list
> Subject: Re: [Tutor] if statement
>
>
On 11/2/2010 3:07 PM, Glen Clark wrote:
sorry:
NumItems = int(input("How many Items: "))
Entries = []
for In in range(0,NumItems):
Entries.append("")
for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))
for In in range(0,NumItems):
prin
On 02/11/10 19:36, christopher.h...@allisontransmission.com wrote:
Glen Clark wrote on 11/02/2010 03:07:18 PM:
in general you should use raw_input instead of input.
> confirmed = int(input("Are you happy with this? (y/n): ")
>
It would appear that Glen is using python 3.x as he used the pri
"Glen Clark" wrote
confirmed = int(input("Are you happy with this? (y/n): ")
if confirmed == "y":
count the parens.
It thinks you are trying to do:
confimed = int(input('') if foo else bar)
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
__
On 11/2/2010 12:07 PM Glen Clark said...
sorry:
NumItems = int(input("How many Items: "))
Entries = []
for In in range(0,NumItems):
Entries.append("")
for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))
for In in range(0,NumItems):
pri
On Tue, Nov 2, 2010 at 3:34 PM, Adam Bark wrote:
> On 02/11/10 19:07, Glen Clark wrote:
>
>> sorry:
>>
>> NumItems = int(input("How many Items: "))
>>
>>
>> Entries = []
>> for In in range(0,NumItems):
>>Entries.append("")
>>
>>
>>
>> for In in range(0,NumItems):
>>Entries[In]=str(input("
Glen Clark wrote on 11/02/2010 03:07:18 PM:
in general you should use raw_input instead of input.
> confirmed = int(input("Are you happy with this? (y/n): ")
>
you are missing a closing parenthesis above, and converting a string (y,n)
to and int
> if confirmed == "y":
you are comparing an in
Okay,
Thank you very much for the help guys :)
On a side note.. I didn't know you could do something like this:
x = z if
(thus why I needed the closing parenthesis)
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription o
On Tue, Nov 2, 2010 at 3:17 PM, Glen Clark wrote:
> I tried that and it still does not work.
>
> On Tue, 2010-11-02 at 15:13 -0400, James Reynolds wrote:
> > the syntax is:
> >
> >
> > if True:
> > do something that you want to do if the condition you are testing
> > is True, in your case wh
On Tue, Nov 2, 2010 at 1:07 PM, Glen Clark wrote:
> sorry:
>
> NumItems = int(input("How many Items: "))
>
>
> Entries = []
> for In in range(0,NumItems):
> Entries.append("")
>
>
>
> for In in range(0,NumItems):
> Entries[In]=str(input("Enter name " + str(In+1) + ": "))
>
>
> for In in range
On 02/11/10 19:07, Glen Clark wrote:
sorry:
NumItems = int(input("How many Items: "))
Entries = []
for In in range(0,NumItems):
Entries.append("")
for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))
for In in range(0,NumItems):
print(E
I tried that and it still does not work.
On Tue, 2010-11-02 at 15:13 -0400, James Reynolds wrote:
> the syntax is:
>
>
> if True:
> do something that you want to do if the condition you are testing
> is True, in your case when confirmed is "y"
> elif True:
> optional: do something els
the syntax is:
if True:
do something that you want to do if the condition you are testing is
True, in your case when confirmed is "y"
elif True:
optional: do something else when the above condition is false and this
condition is True.
else:
do something else when the above condition
It is not always enough to send just the error.
What construct do you have after the if line?
Make your sample detailed to get useful responses.
Regards.
Sent from my BlackBerry wireless device from MTN
-Original Message-
From: Glen Clark
Sender: tutor-bounces+delegbede=dudupay@p
On 02/11/10 19:02, Glen Clark wrote:
File "/home/glen/workspace/test.py", line 19
if confirmed == "y":
^
SyntaxError: invalid syntax
Why does this not work??? PyDev says "Expected:else"
It's hard to tell without context. Can you send the code around it as well
sorry:
NumItems = int(input("How many Items: "))
Entries = []
for In in range(0,NumItems):
Entries.append("")
for In in range(0,NumItems):
Entries[In]=str(input("Enter name " + str(In+1) + ": "))
for In in range(0,NumItems):
print(Entries[In])
confirmed = int(input("Are
On 11/2/10, Glen Clark wrote:
> File "/home/glen/workspace/test.py", line 19
> if confirmed == "y":
>^
> SyntaxError: invalid syntax
>
> Why does this not work??? PyDev says "Expected:else"
It may help to see the rest of the file, or at least more of the code
surroundi
36 matches
Mail list logo