Re: [Tutor] if statement help

2015-03-29 Thread Danny Yoo
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,

[Tutor] if statement help

2015-03-29 Thread Priya Persaud
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, I am so lost. Thank you

Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-14 Thread Alan Gauld
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:

Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-14 Thread ALAN GAULD
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

Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-06 Thread Alan Gauld
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

Re: [Tutor] If statement The Python Tutorial 3.4.1

2014-09-06 Thread Joel Goldstick
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

[Tutor] If statement The Python Tutorial 3.4.1

2014-09-06 Thread Gregory Donaldson
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

Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Dave Angel
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

Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Steven D'Aprano
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

Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Steven D'Aprano
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

Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Dave Angel
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

Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Dave Angel
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

Re: [Tutor] if statement problems(noob question)

2013-04-08 Thread Woody 544
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

[Tutor] if statement problems(noob question)

2013-04-08 Thread Max Smith
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): if x and y == int or float:

Re: [Tutor] If statement optimization

2011-09-16 Thread bodsda
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

Re: [Tutor] If statement optimization

2011-09-16 Thread Steven D'Aprano
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

[Tutor] If statement optimization

2011-09-16 Thread bodsda
Hi, In a normal if,elif,elif,...,else statement, are the conditions checked in a linear fashion? I am wondering if I should be making an effort to put the most likely true condition at the beginning of the block Thanks, Bodsda Sent from my BlackBerry® wireless device _

Re: [Tutor] if statement

2011-06-10 Thread Jeremy G Clark
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

Re: [Tutor] if statement

2011-06-08 Thread Steven D'Aprano
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

Re: [Tutor] if statement

2011-06-07 Thread Alan Gauld
"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(>>>)

Re: [Tutor] if statement

2011-06-07 Thread Andre Engels
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

[Tutor] if statement

2011-06-07 Thread Matthew Brunt
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 problem i'm having is

Re: [Tutor] if statement

2010-11-04 Thread Francesco Loffredo
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

Re: [Tutor] if statement

2010-11-02 Thread Alan Gauld
"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

Re: [Tutor] if statement

2010-11-02 Thread Robert Berman
> -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 > >

Re: [Tutor] if statement

2010-11-02 Thread bob gailer
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

Re: [Tutor] if statement

2010-11-02 Thread Adam Bark
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

Re: [Tutor] if statement

2010-11-02 Thread Alan Gauld
"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/ __

Re: [Tutor] if statement

2010-11-02 Thread Emile van Sebille
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

Re: [Tutor] if statement

2010-11-02 Thread Joel Goldstick
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("

Re: [Tutor] if statement

2010-11-02 Thread christopher . henk
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

Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
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

Re: [Tutor] if statement

2010-11-02 Thread Joel Goldstick
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

Re: [Tutor] if statement

2010-11-02 Thread Vince Spicer
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

Re: [Tutor] if statement

2010-11-02 Thread Adam Bark
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

Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
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

Re: [Tutor] if statement

2010-11-02 Thread James Reynolds
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

Re: [Tutor] if statement

2010-11-02 Thread delegbede
@python.org Date: Tue, 02 Nov 2010 19:02:15 To: python mail list Subject: [Tutor] if statement File "/home/glen/workspace/test.py", line 19 if confirmed == "y": ^ SyntaxError: invalid syntax Why does this not work??? PyDev

Re: [Tutor] if statement

2010-11-02 Thread Adam Bark
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

Re: [Tutor] if statement

2010-11-02 Thread Glen Clark
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

Re: [Tutor] if statement

2010-11-02 Thread Alex Hall
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

[Tutor] if statement

2010-11-02 Thread Glen Clark
File "/home/glen/workspace/test.py", line 19 if confirmed == "y": ^ SyntaxError: invalid syntax Why does this not work??? PyDev says "Expected:else" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscriptio

[Tutor] If statement isn't working

2010-10-29 Thread Susana Iraiis Delgado Rodriguez
Hello members: I'm trying to validate the existence of a file by an if statement, but it isn't working correctly. The module is a crawler that writes to excel some attributes from the files it finds. folders = None # look in this (root) folder for files with specified extension for root, folders