Re: [Tutor] [Python-Help] Writing hello world

2019-06-29 Thread Bob Gailer
On Jun 28, 2019 9:26 AM, "Erastus muriithi" 
wrote:
>
> Iam a student..iam interested in learning python,,I don't know how to
study this python.kindly help me how to go about it..Thankyou

First make sure you have python installed on your computer. If you need
help with that let us know what kind of computer and operating system you
are using.

At the python. Org website you will find links to tutorials. Try some of
these out.

Direct future emails to tutor@python.org.
Always reply all so a copy goes back to the list.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Alan Gauld via Tutor
On 26/10/2018 18:20, Adam Eyring wrote:

> beef = (beefmeals * 15.95)

Note that the parens here are completely redundant.
They don't break anything but neither do they
contribute anything.

WE already have LISP(*) for those who love parens,
no need for (so many of) them in Python

(*)Lots of Irrelevant Silly Parentheses :

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Adam Eyring
On Fri, Oct 26, 2018 at 3:03 PM Bob Gailer  wrote:

> On Oct 26, 2018 1:20 PM, "Adam Eyring"  wrote:
> >
> > Try this cleaned up version with colons in the right places, dollar
> signs removed, and other corrections:
>
> Does it do what you want?
>
> > beefmeals=int(input("Enter number of beef meals: "))
> > shitmeals=int(input("Enter number of vegan meals: "))
> > party = beefmeals + shitmeals
> > print("Total meals", party)
> > a = 0
> > b = 0
> > c = 0
>
> There is no need for three variables here. You only need one to represent
> room cost. If you make that change then you will also not need to
> initialize the room cost variable. Makes the code simpler to maintain and
> read and understand.
>
> > if party <= 50:
> >
> > a=75
> > print("Room cost $75")
>
> If you use one variable for room cost then you can use just one print just
> above the room tax line.
>
> > elif party <= 150:
> >
> > b=150
> > print("Room cost $150")
> > else:
> > c=250
> > print("Room cost $250")
> > roomtax = party * 0.065
> > print("Room tx", roomtax)
> > print("Beef Meals", beefmeals)
> > beef = (beefmeals * 15.95)
> > print("Beef cost", beef)
> > print("Vegan Meals", shitmeals)
> > shit = (shitmeals * 10.95)
> > print("Vegan cost", shit)
> > cost=(beef + shit)
> > grat= cost * 0.18
> > print("Gratuity", grat)
> > GT = print("Grand total", grat + beef + shit + a + b + c)
>
> The print function always returns None. Therefore the effect of this
> statement is to assign None to GT. Also note that you don't use GT later on.
>

You're right - GT is not needed. The print does work with or without "GT
=" in Python 3.6.5, though.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Adam Eyring
Try this cleaned up version with colons in the right places, dollar signs
removed, and other corrections:

beefmeals=int(input("Enter number of beef meals: "))
shitmeals=int(input("Enter number of vegan meals: "))
party = beefmeals + shitmeals
print("Total meals", party)
a = 0
b = 0
c = 0
if party <= 50:
a=75
print("Room cost $75")
elif party <= 150:
b=150
print("Room cost $150")
else:
c=250
print("Room cost $250")
roomtax = party * 0.065
print("Room tx", roomtax)
print("Beef Meals", beefmeals)
beef = (beefmeals * 15.95)
print("Beef cost", beef)
print("Vegan Meals", shitmeals)
shit = (shitmeals * 10.95)
print("Vegan cost", shit)
cost=(beef + shit)
grat= cost * 0.18
print("Gratuity", grat)
GT = print("Grand total", grat + beef + shit + a + b + c)

On Fri, Oct 26, 2018 at 7:28 AM Bob Gailer  wrote:

> On Oct 26, 2018 6:11 AM, "Ben Placella" 
> wrote:
> >
> > I need to write code that runs a  cost calculating program with many
> > different variables and I honestly don't understand it
>
> Could you be more specific? What exactly don't you understand, or even
> better what do you understand?
>
> my code is:
>
> How could you have written so much code without understanding it?
>
> > beefmeals=int(input("Enter number of beef meals: "))
> > shitmeals=int(input("Enter number of vegan meals: "))
> > party=beefmeals+shitmeals
> > print(party)
> > if party<=50
>
> Something is missing from that last statement. Can you tell what it is? Do
> you know how to find out? Hint use help.
>
> Hint 2 it is also missing from the elif and else statements.
>
> > a=75
> > print("Room cost $75")
> > elif party <=150
> > b=150
> > print("Room cost $150")
> > else
> > c=250
> > print("Room cost $250")
> > roomtax=party*0.065
> > print(roomtax)
> > print("Beef Meals", beefmeals)
> > $beef=(beefmeals*15.95)
> > print($beef)
> > print("Beef cost", $$beef)
> > print("Vegan Meals", shitmeals)
> > $shit=(shitmeals*10.95)
> > print($shit)
> > cost=($beef+$shit)
> > grat=cost*0.18)
> > print(grat)
> > GT=(grat+$beef+$shit+(a,b,c))
>
> There is a convention in Python that and all uppercase name is a constant.
> This is not a requirement.
>
> > print(GT)
> >
> > This is what the output is supposed to be:
>
> I don't see any output here. Alan''s responses may help you figure that
> out.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Bob Gailer
On Oct 26, 2018 1:20 PM, "Adam Eyring"  wrote:
>
> Try this cleaned up version with colons in the right places, dollar signs
removed, and other corrections:

Does it do what you want?

> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))
> party = beefmeals + shitmeals
> print("Total meals", party)
> a = 0
> b = 0
> c = 0

There is no need for three variables here. You only need one to represent
room cost. If you make that change then you will also not need to
initialize the room cost variable. Makes the code simpler to maintain and
read and understand.

> if party <= 50:
>
> a=75
> print("Room cost $75")

If you use one variable for room cost then you can use just one print just
above the room tax line.

> elif party <= 150:
>
> b=150
> print("Room cost $150")
> else:
> c=250
> print("Room cost $250")
> roomtax = party * 0.065
> print("Room tx", roomtax)
> print("Beef Meals", beefmeals)
> beef = (beefmeals * 15.95)
> print("Beef cost", beef)
> print("Vegan Meals", shitmeals)
> shit = (shitmeals * 10.95)
> print("Vegan cost", shit)
> cost=(beef + shit)
> grat= cost * 0.18
> print("Gratuity", grat)
> GT = print("Grand total", grat + beef + shit + a + b + c)

The print function always returns None. Therefore the effect of this
statement is to assign None to GT. Also note that you don't use GT later on.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Bob Gailer
On Oct 26, 2018 6:11 AM, "Ben Placella"  wrote:
>
> I need to write code that runs a  cost calculating program with many
> different variables and I honestly don't understand it

Could you be more specific? What exactly don't you understand, or even
better what do you understand?

my code is:

How could you have written so much code without understanding it?

> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))
> party=beefmeals+shitmeals
> print(party)
> if party<=50

Something is missing from that last statement. Can you tell what it is? Do
you know how to find out? Hint use help.

Hint 2 it is also missing from the elif and else statements.

> a=75
> print("Room cost $75")
> elif party <=150
> b=150
> print("Room cost $150")
> else
> c=250
> print("Room cost $250")
> roomtax=party*0.065
> print(roomtax)
> print("Beef Meals", beefmeals)
> $beef=(beefmeals*15.95)
> print($beef)
> print("Beef cost", $$beef)
> print("Vegan Meals", shitmeals)
> $shit=(shitmeals*10.95)
> print($shit)
> cost=($beef+$shit)
> grat=cost*0.18)
> print(grat)
> GT=(grat+$beef+$shit+(a,b,c))

There is a convention in Python that and all uppercase name is a constant.
This is not a requirement.

> print(GT)
>
> This is what the output is supposed to be:

I don't see any output here. Alan''s responses may help you figure that out.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Alan Gauld via Tutor
On 25/10/2018 23:14, Ben Placella wrote:

Please always post code in plain text not HTML or Rich text.
Otherwise we lose all the formatting which is important in Python.

> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))
> party=beefmeals+shitmeals
> print(party)
> if party<=50

Python control statements are terminated by a colon(:)

> $beef=(beefmeals*15.95)

$ signs in front of variable names are an error in Python


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help (shits killing me)

2018-10-26 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 06:13:31PM -0400, Ben Placella wrote:
> So I have to make a fibonacci sequence, and I'm not sure what is wrong with
> my code
[...]

> attached is a photo of what the output SHOULD look like

No it isn't. For security (anti-spam, anti-virus) reasons, this mailing 
list deletes non-text attachments.

Code is text. Unless you edit your code with Photoshop, don't take 
screenshots or photos of the code. COPY AND PASTE the code, and any 
expected results, or error messages, as TEXT.

Text can be copied, edited, and pasted into the interpreter and run.

Photos of text can't be edited, or run in the interpeter. Screen-readers 
can't read them, making them invisible to the blind or visually 
impaired. Photos of text are useless for programming.

When you run your code, what error do you get? COPY AND PASTE the entire 
traceback, starting from the line "Traceback: ..." and including the 
error message at the end.


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 06:14:41PM -0400, Ben Placella wrote:
> I need to write code that runs a  cost calculating program with many
> different variables and I honestly don't understand it, my code is:
> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))

What version of Python are you using?

> party=beefmeals+shitmeals
> print(party)
> if party<=50
> a=75

You have lost the indentation, making your code invalid.

Also, you are probably getting a SyntaxError when you try to run your 
code. As always, please COPY AND PASTE (don't retype it from memory, or 
take a photo) the entire traceback, starting from the line 
"Traceback..." and ending with the error message.


> print("Room cost $75")
> elif party <=150
> b=150
> print("Room cost $150")
> else
> c=250
> print("Room cost $250")

That's two more syntax errors.


> $beef=(beefmeals*15.95)

Dollar signs aren't used for Python variables.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help (shits killing me)

2018-10-26 Thread Alan Gauld via Tutor
Plain text is preferred for code since otherwise the mail
system removes all indentation making the code hard to understand.

On 25/10/2018 23:13, Ben Placella wrote:
> So I have to make a fibonacci sequence, and I'm not sure what is wrong with
> my code
> #This program illustrates the fibonacci sequence
> nterms=int(input("Please enter how many terms you would like to know: "))
> n1 = 1
> n2 = 1
> count = 0
> if nterms <= 0:
> print("Please enter a positive integer")
> elif nterms == 1:
> print("Fibonacci sequence upto",nterms,":")
> print(n1)
> else:
> print("Fibonacci sequence upto",nterms,":")
> while count < nterms:
> print(n1,end=' , ')
> nth = n1 + n

I suspect that n should be n2?

> n1 = n2
> n2 = nth

BTW in Python you can do that set of assignments more
concisely as

n1,n2 = n2, n1+n2

with no temporary variable required.

> count += 1

And rather than using a while loop and manually
maintaining a count you could just use a for loop:

for count in range(nterms):

It's slightly more reliable and a lot more "pythonic".

> attached is a photo of what the output SHOULD look like

This is a text only list so images or other binary files
are stripped off by the server. Please, in future,
cut n' paste any output into the mail body.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help (shits killing me)

2018-10-26 Thread Andrew Van Valkenburg
nth = n1 + n

I don't see where n is defined anywhere.  Should be n2?

On Fri, Oct 26, 2018 at 6:09 AM Ben Placella 
wrote:

> So I have to make a fibonacci sequence, and I'm not sure what is wrong with
> my code
> #This program illustrates the fibonacci sequence
> nterms=int(input("Please enter how many terms you would like to know: "))
> n1 = 1
> n2 = 1
> count = 0
> if nterms <= 0:
> print("Please enter a positive integer")
> elif nterms == 1:
> print("Fibonacci sequence upto",nterms,":")
> print(n1)
> else:
> print("Fibonacci sequence upto",nterms,":")
> while count < nterms:
> print(n1,end=' , ')
> nth = n1 + n
> n1 = n2
> n2 = nth
> count += 1
>
> attached is a photo of what the output SHOULD look like
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2018-10-26 Thread Ben Placella
I need to write code that runs a  cost calculating program with many
different variables and I honestly don't understand it, my code is:
beefmeals=int(input("Enter number of beef meals: "))
shitmeals=int(input("Enter number of vegan meals: "))
party=beefmeals+shitmeals
print(party)
if party<=50
a=75
print("Room cost $75")
elif party <=150
b=150
print("Room cost $150")
else
c=250
print("Room cost $250")
roomtax=party*0.065
print(roomtax)
print("Beef Meals", beefmeals)
$beef=(beefmeals*15.95)
print($beef)
print("Beef cost", $$beef)
print("Vegan Meals", shitmeals)
$shit=(shitmeals*10.95)
print($shit)
cost=($beef+$shit)
grat=cost*0.18)
print(grat)
GT=(grat+$beef+$shit+(a,b,c))
print(GT)

This is what the output is supposed to be:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help (shits killing me)

2018-10-26 Thread Ben Placella
So I have to make a fibonacci sequence, and I'm not sure what is wrong with
my code
#This program illustrates the fibonacci sequence
nterms=int(input("Please enter how many terms you would like to know: "))
n1 = 1
n2 = 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence upto",nterms,":")
while count < nterms:
print(n1,end=' , ')
nth = n1 + n
n1 = n2
n2 = nth
count += 1

attached is a photo of what the output SHOULD look like
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2018-04-02 Thread Alan Gauld via Tutor
On 03/04/18 01:19, Steven D'Aprano wrote:
>
>> if Grade not in 'A','B','C','D','E','F':
> Actually, that returns a tuple consisting of a flag plus five more 
> strings:
>
> py> 'A' in 'A','B','C', 'D', 'E', 'F'
> (True, 'B','C', 'D', 'E', 'F')

Although in the context of the program the colon at the end ensures
we get a syntax error so the mistake is found pretty quickly...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2018-04-02 Thread Alan Gauld via Tutor
On 03/04/18 01:19, Steven D'Aprano wrote:
> On Tue, Apr 03, 2018 at 01:00:59AM +0100, Alan Gauld via Tutor wrote:
>
>> You need to use 'in' instead. That will check whether
>> or not Grade is *one* of the values in the tuple.
>>
>> if Grade not in 'A','B','C','D','E','F':
> Actually, that returns a tuple consisting of a flag plus five more 
> strings:
>
> py> 'A' in 'A','B','C', 'D', 'E', 'F'
> (True, 'B','C', 'D', 'E', 'F')
>
> We need to put round brackets (parentheses) around the scores:
>
> if Grade not in ('A','B','C','D','E','F'):

Oops, yes, a cut n' paste error, I forgot to add the parens.
mea culpa!

-- 

Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2018-04-02 Thread Steven D'Aprano
On Tue, Apr 03, 2018 at 01:00:59AM +0100, Alan Gauld via Tutor wrote:

> You need to use 'in' instead. That will check whether
> or not Grade is *one* of the values in the tuple.
> 
> if Grade not in 'A','B','C','D','E','F':

Actually, that returns a tuple consisting of a flag plus five more 
strings:

py> 'A' in 'A','B','C', 'D', 'E', 'F'
(True, 'B','C', 'D', 'E', 'F')

We need to put round brackets (parentheses) around the scores:

if Grade not in ('A','B','C','D','E','F'):


Don't be tempted to take a short-cut:

# WRONG!
if Grade not in 'ABCDEF':

as that would accepted grades like "CDEF" and "BC".



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2018-04-02 Thread Alan Gauld via Tutor
On 02/04/18 23:44, Shannon Evans via Tutor wrote:
> Hi, I am trying to write a code with if statements but the code keeps just
> repeating and not carrying on.

There are quite a few problems here, see comments below.

> while True:
> try:
> Grade = int(raw_input("Please enter your Grade: "))

You are trying to convert the input to an integer.
But A-F will not convert so thats the first problem
right there.

> except ValueError:
> print("Error, Please enter A, B, C, D, E or F")
> continue

And here you prompt for an A-F input not an integer.


> if Grade <> 'A','B','C','D','E','F':
This doesn't do what you think. It tests to see if Grade
is not equal to a tuple of values ('A','B','C','D','E','F')
You need to use 'in' instead. That will check whether
or not Grade is *one* of the values in the tuple.

if Grade not in 'A','B','C','D','E','F':

> print ("Error, Please enter A, B, C, D, E or F")
> continue
> else:#Grade succesfully completed, and we're happy with its value.
> #ready to exit the loop.
> break

Taking out the conversion to int() would be a good start.
Then change the if test to use 'in'.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2018-04-02 Thread Steven D'Aprano
On Mon, Apr 02, 2018 at 11:44:39PM +0100, Shannon Evans via Tutor wrote:
> Hi, I am trying to write a code with if statements but the code keeps just
> repeating and not carrying on.
> I am trying to get user to input a grade, either A, B, C, D, E or F and
> trying to have an error message if anything but these values are inputted.
> This is what i've wrote so far:
> 
> while True:
> try:
> Grade = int(raw_input("Please enter your Grade: "))

Here you convert the user's input into an integer, a number such as 1, 
2, 57, 92746 etc. If that *fails*, you run this block:

> except ValueError:
> print("Error, Please enter A, B, C, D, E or F")
> continue

and start again.

If it succeeds, because the user entered (let's say) 99, then you run 
another test:

> if Grade <> 'A','B','C','D','E','F':
> print ("Error, Please enter A, B, C, D, E or F")
> continue

That will ALWAYS fail, because you are trying to compare the integer 99 
(for example) with the tuple of six characters:

99 <> ('A', 'B','C','D','E','F')

which is always false. So that block will ALWAYS fail, and you always go 
back to the start.




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help

2018-04-02 Thread Shannon Evans via Tutor
Hi, I am trying to write a code with if statements but the code keeps just
repeating and not carrying on.
I am trying to get user to input a grade, either A, B, C, D, E or F and
trying to have an error message if anything but these values are inputted.
This is what i've wrote so far:

while True:
try:
Grade = int(raw_input("Please enter your Grade: "))
except ValueError:
print("Error, Please enter A, B, C, D, E or F")
continue

if Grade <> 'A','B','C','D','E','F':
print ("Error, Please enter A, B, C, D, E or F")
continue
else:#Grade succesfully completed, and we're happy with its value.
#ready to exit the loop.
break

When trying to run it just writes the error message for any letter you
input.
Any hep would be appreciated thank you!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHON HELP

2018-03-15 Thread Alan Gauld via Tutor
On 15/03/18 13:42, Prashanth Ram wrote:

> My code is working well in localhost but when I try to open that in VPS
> server I'm failing in running that code. I'm getting errors. I have
> installed Chrome and it's drivers. Even though I'm facing errors.
> 
> I request your team to help me in this. Please find the attachments

This is a text based email list so any binary attachments get stripped
by the server for security reasons. Please send the code plus any error
messages as text within your emails. Alternatively post images on a web
site and send a link.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHON HELP

2018-03-15 Thread David Rock

> On Mar 15, 2018, at 08:42, Prashanth Ram  wrote:
> 
> I'm a beginner in Python. I have written a code to open browsers using
> selenium framework. I have purchased a Virtual Private Server (VPS) with
> CentOS 6.9 installed from GoDaddy.
> 
> My code is working well in localhost but when I try to open that in VPS
> server I'm failing in running that code. I'm getting errors. I have
> installed Chrome and it's drivers. Even though I'm facing errors.
> 
> I request your team to help me in this. Please find the attachments
> 

Welcome,

Your attachments did not come through.  This list generally only works with 
in-line text.  If you post your code, what you expect and what the errors are, 
we will have a better chance of helping.

Being a tutor list, help with the selenium framework is not guaranteed, though. 
 Hopefully your issue is something basic.


— 
David Rock
da...@graniteweb.com




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] PYTHON HELP

2018-03-15 Thread Prashanth Ram
Dear Sir/Madam,

I'm a beginner in Python. I have written a code to open browsers using
selenium framework. I have purchased a Virtual Private Server (VPS) with
CentOS 6.9 installed from GoDaddy.

My code is working well in localhost but when I try to open that in VPS
server I'm failing in running that code. I'm getting errors. I have
installed Chrome and it's drivers. Even though I'm facing errors.

I request your team to help me in this. Please find the attachments

Thanks & Regards,
Prashanth R
ITW Travel and Leisure Pvt Ltd.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2017-09-16 Thread Mats Wichmann
On 09/15/2017 10:25 AM, Alan Gauld via Tutor wrote:
> On 15/09/17 04:08, Pratyusha Thundena wrote:
>> How do check to see if string ‘garden’ contains a 
>> vowel(a, e , i , o, u , or y) using a for loop? 
> 
> Hi, this sounds like homework and we won't do
> your homework for you, but we do give hints.
> 
> How would you do this without a computer?
> There are (at least) two ways:
> 1) you can check each letter in your word and
>see if it is a vowel.
> 2) we can check each vowel and see if it is
>in your word
> 
> A for loop gives you each item in a sequence one
> by one so would work in either solution.
> 
> Let's consider option 1 in pseudo-code:
> 
> for each letter in word:
> if letter is a vowel:
>do something... what?
> 
> So that leads to two questions:
> 1) how do you tell if a letter is a vowel?
>Hint: look at what the string 'in' operator does
> 2) What do you want to do if you find a vowel?
>print something? exit? or what...?
> 
> See if that helps, if you still need help come back with
> a specific question (the more specific the question, the
> more specific will be the answer) and show us your code
> plus any error messages you received.

It also leads to a chance to lecture (just what you wanted, right):

Computer programming is hard.  One of the reasons it's hard is because
you don't always know exactly what the problem you're trying to solve
consists of. Here in a learning situation it's going to be safe, but in
the real world you will often find what seemed obvious to the person who
framed the requirement may be full of ambiguities or subtle effects. Like:

Does a string contain a vowel? - you list the 5 1/2 vowels from English.

y is the 1/2: grammatically, it is considered a vowel in words like
'baby' or 'sky', but it is a consonant in words like 'yes' or 'yogurt'.
Should your solution take this into account? It would make the code
vastly more complicated, because you would have to teach it to divide
the word correctly into syllables, and apply the rule for when it is
treated as a consonant. Which means you probably need to start by
validating that the input is a correct word.  Of course you are not
going to worry about that solving a classroom problem (unless the
instructor or book is being very sneaky).

and then there is the complication of language.  should your solution
work for English only? Or for other languages? I grew up speaking a
language where åäö are vowels.  If you are trying to process information
entered by a user in a website, for example, there's a pretty reasonable
chance that it should understand other languages, and then you need to
look into character-set specifications, unicode, etc.

Enjoy learning Python!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2017-09-15 Thread Alan Gauld via Tutor
On 15/09/17 04:08, Pratyusha Thundena wrote:
> How do check to see if string ‘garden’ contains a 
> vowel(a, e , i , o, u , or y) using a for loop? 

Hi, this sounds like homework and we won't do
your homework for you, but we do give hints.

How would you do this without a computer?
There are (at least) two ways:
1) you can check each letter in your word and
   see if it is a vowel.
2) we can check each vowel and see if it is
   in your word

A for loop gives you each item in a sequence one
by one so would work in either solution.

Let's consider option 1 in pseudo-code:

for each letter in word:
if letter is a vowel:
   do something... what?

So that leads to two questions:
1) how do you tell if a letter is a vowel?
   Hint: look at what the string 'in' operator does
2) What do you want to do if you find a vowel?
   print something? exit? or what...?

See if that helps, if you still need help come back with
a specific question (the more specific the question, the
more specific will be the answer) and show us your code
plus any error messages you received.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2017-07-23 Thread Cameron Simpson

On 23Jul2017 13:40, Winonah Ojanen  wrote:

I also tried the correct command for the mac ox s in terminal shell,
running:

Jims-MacBook-Pro-2:~ Jim$
PYTHONPATH="/Users/Jim/Documents/illustris_python:$PYTHONPATH

export PYTHONPATH

[...]

I did use the pip command and am attempting to add the files to my python
path. I used
 import sys
sys.path.append("/Users/Jim/Documents/illustris_python")


Please always reply-all or reply-to-list.

The python path is a list of places to look for modules. By adding 
'../illustris_python' you're implying you want the module to be at 
'../illustris_python/illustris_python'.


See if using '/Users/Jim/Documents' finds the module. Then move it to a better 
(more targeted) directory and use that directory's name :-)


Cheers,
Cameron Simpson 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2017-07-22 Thread Cameron Simpson

On 23Jul2017 00:20, Alan Gauld  wrote:

On 22/07/17 19:14, Winonah Ojanen wrote:

using python with anaconda in jupiter notebook. However, I am having


Usual caveat: The tutor list is targeted at the standard library
so any help for non standard library modules is best sought from
the library support fora. In this case that includes the SciPy forum
and any illustris one.


Though arguably the OP's problem is an import issue, not really module 
specific.



That having been said, I'll take a guess...

$ mkdir Illustris-3
$ mkdir Illustris-3/groups_135

Are these folders in your PYTHONPATH? If not Python will not find them.


import illustris_python as il
---
ModuleNotFoundError   Traceback (most recent call last)


The OP cded into the new dir; I'd normally expect things to be found if the 
module was a local file/dir. However...



For some reason the computer is not recognizing this as a file on my
computer. The CCA folks says this is a coding problem and not an illustris
problem. any ideas to get me past this? I may also need help getting
farther into the download process.


I just ran the OP's download command:

 wget -nd -nc -nv -e robots=off -l 1 -r -A hdf5 --content-disposition --header="API-Key: 
d522db2e1b33e36d3b365cc9ac1c2c5d" 
"http://www.illustris-project.org/api/Illustris-3/files/groupcat-135/?format=api;

This doesn't seem to download any Python code at all. It does get a couple of 
HDF files, presumably with data to work with.


So the issue is initially that the module isn't present anywhere. Looking at 
the instructions cited , 
they only cover fetching som data and working; they presume the software is 
already present. I don't immediately see actual software installation 
instructions, and it is not presented in PyPI.


Most like the OP will have to install the software directly from:

 https://bitbucket.org/illustris/illustris_python

This command:

 hg clone https://bitbucket.org/illustris/stris_pythonillustris_python

should produce an "illustris_python" in the current directory, and then her 
import command will find it.


However, there are other prerequisites. This pip command:

 pip install h5py numpy

seems to resolve them. The OP will need to use Python 2 because the module 
seems to rely on a relative import (for its "util.py" file).


Cheers,
Cameron Simpson 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2017-07-22 Thread Alan Gauld via Tutor
On 22/07/17 19:14, Winonah Ojanen wrote:

> using python with anaconda in jupiter notebook. However, I am having

Usual caveat: The tutor list is targeted at the standard library
so any help for non standard library modules is best sought from
the library support fora. In this case that includes the SciPy forum
and any illustris one.

That having been said, I'll take a guess...

> $ mkdir Illustris-3
> $ mkdir Illustris-3/groups_135

Are these folders in your PYTHONPATH? If not Python will not find them.

> import illustris_python as il
> ---
> ModuleNotFoundError   Traceback (most recent call last)


> For some reason the computer is not recognizing this as a file on my
> computer. The CCA folks says this is a coding problem and not an illustris
> problem. any ideas to get me past this? I may also need help getting
> farther into the download process.
You probably need to add the folders to PYTHONPATH environment
variable. How you do that depends on your shell. But any shell
tutorial will show you how. The format of PYTHONPATH is the same
as most other Unix PATHs - eg $PATH, $MANPATH, etc

The other thing to check is that there is not a pip compatible
installer which will put it in the right place for you... often
somewhere in site-packages.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2017-07-22 Thread Winonah Ojanen
Hello,
I am an intern working with the Center for Computational Astrophysics
through the American Museum of Natural History as an astrophysics intern. I
am working with a galaxy simulation program called "illustris" which you
can find at illustris-project.org. I am working to download example scripts
from the website to work with merger trees and galaxy simulation through
using python with anaconda in jupiter notebook. However, I am having
trouble o the coding side with importing the example scripts through
jupiter notebook. original instructions are here:
http://www.illustris-project.org/data/docs/scripts/
I started by downloading the example scripts for the python version from
bitbucket. I have them download on my computer in a folder that is named
"illustris_python". I did the first commands through jupiter notebook and
they were successful :
$ mkdir Illustris-3
$ mkdir Illustris-3/groups_135
$ cd Illustris-3/groups_135/
I got a success message for creating the directory.
I then went to the link to download the illustris data I need:
$ wget -nd -nc -nv -e robots=off -l 1 -r -A hdf5 --content-disposition
--header="API-Key: d522db2e1b33e36d3b365cc9ac1c2c5d" "
http://www.illustris-project.org/api/Illustris-3/files/groupcat-135/?format=api
"
download successfully.
Then the next command is the have python important the example scripts
which i downloaded earlier, and named as "illustris_python":
$ python
>>> import illustris_python as il
>>>
The computer is giving me this error message:
import illustris_python as il
---
ModuleNotFoundError   Traceback (most recent call last)
 in ()
> 1 import illustris_python as il

ModuleNotFoundError: No module named 'illustris_python'

For some reason the computer is not recognizing this as a file on my
computer. The CCA folks says this is a coding problem and not an illustris
problem. any ideas to get me past this? I may also need help getting
farther into the download process.


Thank you,
Winonah Ojanen
Astrophysics Research Intern at the American Museum of Natural History
Education/ Ojibwe Language Undergraduate at the College of Saint Scholastica
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python - help with something most essential

2017-06-12 Thread Abdur-Rahmaan Janhangeer
i might add that
with open( . . .

instead of

foo = open( . . .

also shows some maturity in py

Abdur-Rahmaan Janhangeer,
Mauritius
abdurrahmaanjanhangeer.wordpress.com

On 11 Jun 2017 12:33, "Peter Otten" <__pete...@web.de> wrote:

> Japhy Bartlett wrote:
>
> > I'm not sure that they cared about how you used file.readlines(), I think
> > the memory comment was a hint about instantiating Counter()s
>
> Then they would have been clueless ;)
>
> Both Schtvveer's original script and his subsequent "Verschlimmbesserung"
> --
> beautiful german word for making things worse when trying to improve them
> --
> use only two Counters at any given time. The second version is very
> inefficient because it builds the same Counter over and over again -- but
> this does not affect peak memory usage much.
>
> Here's the original version that triggered the comment:
>
> [Schtvveer Schvrveve]
>
> > import sys
> > from collections import Counter
> >
> > def main(args):
> > filename = args[1]
> > word = args[2]
> > print countAnagrams(word, filename)
> >
> > def countAnagrams(word, filename):
> >
> > fileContent = readFile(filename)
> >
> > counter = Counter(word)
> > num_of_anagrams = 0
> >
> > for i in range(0, len(fileContent)):
> > if counter == Counter(fileContent[i]):
> > num_of_anagrams += 1
> >
> > return num_of_anagrams
> >
> > def readFile(filename):
> >
> > with open(filename) as f:
> > content = f.readlines()
> >
> > content = [x.strip() for x in content]
> >
> > return content
> >
> > if __name__ == '__main__':
> > main(sys.argv)
> >
>
> referenced as before.py below, and here's a variant that removes
> readlines(), range(), and the [x.strip() for x in content] list
> comprehension, the goal being minimal changes, not code as I would write it
> from scratch.
>
> # after.py
> import sys
> from collections import Counter
>
> def main(args):
> filename = args[1]
> word = args[2]
> print countAnagrams(word, filename)
>
> def countAnagrams(word, filename):
>
> fileContent = readFile(filename)
> counter = Counter(word)
> num_of_anagrams = 0
>
> for line in fileContent:
> if counter == Counter(line):
> num_of_anagrams += 1
>
> return num_of_anagrams
>
> def readFile(filename):
> # this relies on garbage collection to close the file
> # which should normally be avoided
> for line in open(filename):
> yield line.strip()
>
> if __name__ == '__main__':
> main(sys.argv)
>
> How to measure memoryview? I found
>  usage-of-a-linux-unix-process> and as test data I use files containing
> 10**5 and 10**6
> integers. With that setup (snipping everything but memory usage from the
> time -v output):
>
> $ /usr/bin/time -v python before.py anagrams5.txt 123
> 6
> Maximum resident set size (kbytes): 17340
> $ /usr/bin/time -v python before.py anagrams6.txt 123
> 6
> Maximum resident set size (kbytes): 117328
>
>
> $ /usr/bin/time -v python after.py anagrams5.txt 123
> 6
> Maximum resident set size (kbytes): 6432
> $ /usr/bin/time -v python after.py anagrams6.txt 123
> 6
> Maximum resident set size (kbytes): 6432
>
> See the pattern? before.py uses O(N) memory, after.py O(1).
>
> Run your own tests if you need more datapoints or prefer a different method
> to measure memory consumption.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python - help with something most essential

2017-06-11 Thread Peter Otten
Japhy Bartlett wrote:

> I'm not sure that they cared about how you used file.readlines(), I think
> the memory comment was a hint about instantiating Counter()s

Then they would have been clueless ;)

Both Schtvveer's original script and his subsequent "Verschlimmbesserung" -- 
beautiful german word for making things worse when trying to improve them --  
use only two Counters at any given time. The second version is very 
inefficient because it builds the same Counter over and over again -- but 
this does not affect peak memory usage much.

Here's the original version that triggered the comment:

[Schtvveer Schvrveve]

> import sys
> from collections import Counter
> 
> def main(args):
> filename = args[1]
> word = args[2]
> print countAnagrams(word, filename)
> 
> def countAnagrams(word, filename):
> 
> fileContent = readFile(filename)
> 
> counter = Counter(word)
> num_of_anagrams = 0
> 
> for i in range(0, len(fileContent)):
> if counter == Counter(fileContent[i]):
> num_of_anagrams += 1
> 
> return num_of_anagrams
> 
> def readFile(filename):
> 
> with open(filename) as f:
> content = f.readlines()
> 
> content = [x.strip() for x in content]
> 
> return content
> 
> if __name__ == '__main__':
> main(sys.argv)
> 
 
referenced as before.py below, and here's a variant that removes 
readlines(), range(), and the [x.strip() for x in content] list 
comprehension, the goal being minimal changes, not code as I would write it 
from scratch.

# after.py
import sys
from collections import Counter

def main(args):
filename = args[1]
word = args[2]
print countAnagrams(word, filename)

def countAnagrams(word, filename):

fileContent = readFile(filename)
counter = Counter(word)
num_of_anagrams = 0

for line in fileContent:
if counter == Counter(line):
num_of_anagrams += 1

return num_of_anagrams

def readFile(filename):
# this relies on garbage collection to close the file
# which should normally be avoided
for line in open(filename):
yield line.strip()

if __name__ == '__main__':
main(sys.argv)

How to measure memoryview? I found

 and as test data I use files containing 10**5 and 10**6 
integers. With that setup (snipping everything but memory usage from the 
time -v output):

$ /usr/bin/time -v python before.py anagrams5.txt 123
6
Maximum resident set size (kbytes): 17340
$ /usr/bin/time -v python before.py anagrams6.txt 123
6
Maximum resident set size (kbytes): 117328


$ /usr/bin/time -v python after.py anagrams5.txt 123
6
Maximum resident set size (kbytes): 6432
$ /usr/bin/time -v python after.py anagrams6.txt 123
6
Maximum resident set size (kbytes): 6432

See the pattern? before.py uses O(N) memory, after.py O(1). 

Run your own tests if you need more datapoints or prefer a different method 
to measure memory consumption.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python - help with something most essential

2017-06-10 Thread Japhy Bartlett
It's really awkward the way you're using Counter here... you're making new
instances in every lambda (which is not great for memory usage), and then
not actually using the Counter functionality:

return sum(1 for _ in filter(lambda x: Counter(word) == Counter(x.strip()),
fileContent))

(the whole point of the Counter() is to get sums, you don't need to do any
of this !!)

I'm not sure that they cared about how you used file.readlines(), I think
the memory comment was a hint about instantiating Counter()s


anyhow, all of this can be much much simpler:

"""
sortedword = sorted(inputWord)  # an array of letters in the word, in
alphabetical order
count = 0

with open(filename) as f:
for word in f.read().split(' '):  # iterate over every word in the file
if sorted(word) == sortedword:
count +=1

print count
"""

which could in turn probably be written as a one liner.

So even though you cleaned the code up a bit, it's still quite a bit more
complicated then it needs to be, which makes it seem like your fundamentals
are not great either!





On Tue, Jun 6, 2017 at 2:31 AM, Peter Otten <__pete...@web.de> wrote:

> Schtvveer Schvrveve wrote:
>
> > I need someone's help. I am not proficient in Python and I wish to
> > understand something. I was in a job pre-screening process where I was
> > asked to solve a simple problem.
> >
> > The problem was supposed to be solved in Python and it was supposed to
> > take two arguments: filename and word. The program reads the file which
> is
> > a .txt file containing a bunch of words and counts how many of those
> words
> > in the file are anagrams of the argument.
> >
> > First I concocted this solution:
> >
> > import sys
> > from collections import Counter
> >
> > def main(args):
> > filename = args[1]
> > word = args[2]
> > print countAnagrams(word, filename)
> >
> > def countAnagrams(word, filename):
> >
> > fileContent = readFile(filename)
> >
> > counter = Counter(word)
> > num_of_anagrams = 0
> >
> > for i in range(0, len(fileContent)):
> > if counter == Counter(fileContent[i]):
> > num_of_anagrams += 1
> >
> > return num_of_anagrams
> >
> > def readFile(filename):
> >
> > with open(filename) as f:
> > content = f.readlines()
> >
> > content = [x.strip() for x in content]
> >
> > return content
> >
> > if __name__ == '__main__':
> > main(sys.argv)
> >
> > Very quickly I received this comment:
> >
> > "Can you adjust your solution a bit so you less loops (as little as
> > possible) and also reduce the memory usage footprint of you program?"
> >
> > I tried to rework the methods into this:
> >
> > def countAnagrams(word, filename):
> >
> > fileContent = readFile(filename)
> >
> > return sum(1 for _ in filter(lambda x: Counter(word) ==
> > Counter(x.strip()), fileContent))
> >
> > def readFile(filename):
> >
> > with open(filename) as f:
> > content = f.readlines()
> >
> > return content
> >
> > And I was rejected. I just wish to understand what I could have done for
> > this to be better?
> >
> > I am a Python beginner, so I'm sure there are things I don't know, but I
> > was a bit surprised at the abruptness of the rejection and I'm worried
> I'm
> > doing something profoundly wrong.
>
> for i in range(0, len(stuff)):
> ...
>
> instead of
>
> for item in stuff:
> ...
>
> and
>
> content = file.readlines() # read the whole file into memory
> process(content)
>
> are pretty much the most obvious indicators that you are a total newbie in
> Python. Looks like they weren't willing to give you the time to iron that
> out on the job even though you knew about lambda, Counter, list
> comprehensions and generator expressions which are not newbie stuff.
>
> When upon their hint you did not address the root cause of the unbounded
> memory consumption they might have come to the conclusion that you were
> reproducing snippets you picked up somewhere and thus were cheating.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python - help with something most essential

2017-06-06 Thread Peter Otten
Schtvveer Schvrveve wrote:

> I need someone's help. I am not proficient in Python and I wish to
> understand something. I was in a job pre-screening process where I was
> asked to solve a simple problem.
> 
> The problem was supposed to be solved in Python and it was supposed to
> take two arguments: filename and word. The program reads the file which is
> a .txt file containing a bunch of words and counts how many of those words
> in the file are anagrams of the argument.
> 
> First I concocted this solution:
> 
> import sys
> from collections import Counter
> 
> def main(args):
> filename = args[1]
> word = args[2]
> print countAnagrams(word, filename)
> 
> def countAnagrams(word, filename):
> 
> fileContent = readFile(filename)
> 
> counter = Counter(word)
> num_of_anagrams = 0
> 
> for i in range(0, len(fileContent)):
> if counter == Counter(fileContent[i]):
> num_of_anagrams += 1
> 
> return num_of_anagrams
> 
> def readFile(filename):
> 
> with open(filename) as f:
> content = f.readlines()
> 
> content = [x.strip() for x in content]
> 
> return content
> 
> if __name__ == '__main__':
> main(sys.argv)
> 
> Very quickly I received this comment:
> 
> "Can you adjust your solution a bit so you less loops (as little as
> possible) and also reduce the memory usage footprint of you program?"
> 
> I tried to rework the methods into this:
> 
> def countAnagrams(word, filename):
> 
> fileContent = readFile(filename)
> 
> return sum(1 for _ in filter(lambda x: Counter(word) ==
> Counter(x.strip()), fileContent))
> 
> def readFile(filename):
> 
> with open(filename) as f:
> content = f.readlines()
> 
> return content
> 
> And I was rejected. I just wish to understand what I could have done for
> this to be better?
> 
> I am a Python beginner, so I'm sure there are things I don't know, but I
> was a bit surprised at the abruptness of the rejection and I'm worried I'm
> doing something profoundly wrong.

for i in range(0, len(stuff)):
...

instead of 

for item in stuff:
...

and

content = file.readlines() # read the whole file into memory
process(content)

are pretty much the most obvious indicators that you are a total newbie in 
Python. Looks like they weren't willing to give you the time to iron that 
out on the job even though you knew about lambda, Counter, list 
comprehensions and generator expressions which are not newbie stuff. 

When upon their hint you did not address the root cause of the unbounded 
memory consumption they might have come to the conclusion that you were 
reproducing snippets you picked up somewhere and thus were cheating.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python - help with something most essential

2017-06-05 Thread David Rock

> On Jun 5, 2017, at 09:36, Schtvveer Schvrveve  wrote:
> 
> 
> And I was rejected. I just wish to understand what I could have done for
> this to be better?
> 
> I am a Python beginner, so I'm sure there are things I don't know, but I
> was a bit surprised at the abruptness of the rejection and I'm worried I'm
> doing something profoundly wrong.

The main thing that jumps out to me is the memory issue they asked you to 
address was not addressed.  

In your readFile, you have 

with open(filename) as f:
   content = f.readlines()

Which reads the entire file into memory. They specifically did not want you to 
do that.  
The implication is they were looking for a solution where you read the file 
maybe one line (or even one word) at a time and look for anagrams in smaller 
groups.

—
David
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python - help with something most essential

2017-06-05 Thread Schtvveer Schvrveve
I need someone's help. I am not proficient in Python and I wish to
understand something. I was in a job pre-screening process where I was
asked to solve a simple problem.

The problem was supposed to be solved in Python and it was supposed to take
two arguments: filename and word. The program reads the file which is a
.txt file containing a bunch of words and counts how many of those words in
the file are anagrams of the argument.

First I concocted this solution:

import sys
from collections import Counter

def main(args):
filename = args[1]
word = args[2]
print countAnagrams(word, filename)

def countAnagrams(word, filename):

fileContent = readFile(filename)

counter = Counter(word)
num_of_anagrams = 0

for i in range(0, len(fileContent)):
if counter == Counter(fileContent[i]):
num_of_anagrams += 1

return num_of_anagrams

def readFile(filename):

with open(filename) as f:
content = f.readlines()

content = [x.strip() for x in content]

return content

if __name__ == '__main__':
main(sys.argv)

Very quickly I received this comment:

"Can you adjust your solution a bit so you less loops (as little as
possible) and also reduce the memory usage footprint of you program?"

I tried to rework the methods into this:

def countAnagrams(word, filename):

fileContent = readFile(filename)

return sum(1 for _ in filter(lambda x: Counter(word) ==
Counter(x.strip()), fileContent))

def readFile(filename):

with open(filename) as f:
content = f.readlines()

return content

And I was rejected. I just wish to understand what I could have done for
this to be better?

I am a Python beginner, so I'm sure there are things I don't know, but I
was a bit surprised at the abruptness of the rejection and I'm worried I'm
doing something profoundly wrong.

Thank you in advance
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2017-04-13 Thread George Fischhof
Hi Christina,

you should use an editor or an IDE (Integrated Development Environment) (a
quite good and my favorite IDE is PyCharm
https://www.jetbrains.com/pycharm/download/#section=windows ), write the
script in it,then save,  then run it from the IDE or from command line with
similar command:
python script_name.py

BR,
George

2017-04-13 16:33 GMT+02:00 Christina Hammer :

> Hi,
> I downloaded the newest version of Python on my windows computer and am
> having some trouble using it. I need to save my work because I am using it
> for an online class and am going to have to send it to my professor. But I
> cannot access a tool bar that would allow me to save it. I'm not sure if
> someone can help me with this.
> Thank you
> Christina Hammer
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2017-04-13 Thread Qiao Qiao
If you are going to send it to your professor. Maybe just copy all your
result to a txt file and send the text?

Qiao

Qiao Qiao
Web Engineer

On Thu, Apr 13, 2017 at 10:33 AM, Christina Hammer <
hamme...@mail.montclair.edu> wrote:

> Hi,
> I downloaded the newest version of Python on my windows computer and am
> having some trouble using it. I need to save my work because I am using it
> for an online class and am going to have to send it to my professor. But I
> cannot access a tool bar that would allow me to save it. I'm not sure if
> someone can help me with this.
> Thank you
> Christina Hammer
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2017-04-13 Thread Alan Gauld via Tutor
On 13/04/17 15:33, Christina Hammer wrote:

> I downloaded the newest version of Python on my windows computer and am
> having some trouble using it. I need to save my work because I am using it
> for an online class and am going to have to send it to my professor. But I
> cannot access a tool bar that would allow me to save it. I'm not sure if
> someone can help me with this.

Python is a programming language interpreter, and as such it
does not have a GUI. Instead you create your programs using
a separate program, usually a text editor like Notepad,
or sometjhing more powerful. From there you save the program
as a file ending with .py.

On Windows you can then get Python to execute that file by either
1) Double clicking in Windows explorer (but this often results
in the program starting, running and closing so quickly you
can't see what it did*)
2) Start a command console (CMD.EXE) and type

C:\WINDOWS> python myprogram.py


(*)You can force the program to pause by adding a line
input("Hit ENTER to continue")
in your code.
-

Most Python downloads simplify this process by including a
development tool called IDLE and you should have an entry
for that in your menus. IDLE presents a GUI into which
you can enter python commands or open a new edit window
to type your code. You can then save that as before. But
IDLE also includes menus for running your code from within
IDLE. If you search on YouTube you will find several short
tutorial videos showing how to get started with IDLE.

Here is one specifically for Windows...

https://www.youtube.com/watch?v=5hwG2gEGzVg


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python help

2017-04-13 Thread Christina Hammer
Hi,
I downloaded the newest version of Python on my windows computer and am
having some trouble using it. I need to save my work because I am using it
for an online class and am going to have to send it to my professor. But I
cannot access a tool bar that would allow me to save it. I'm not sure if
someone can help me with this.
Thank you
Christina Hammer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2016-11-16 Thread Alan Gauld via Tutor
On 16/11/16 22:51, Omari Lamar wrote:

> I am looking for assistance with the python language. Can you send out an
> eblast asking that if anyone can offer 1 on 1 assistance via skype to cover
> the basics that would be greatly appreciated.

Further to Bens message, we don't offer private 1-1 tutoring but
simply answer questions and expolain issues on the public mailing
list. Take a look at the list archives to see how it works.

If you want to contribute to the community by asking
questions on the list please comply with the following for best results:

1) Tell us the OS and Python version
2) Show us the code and the full error text, if any.
3) Explain in simple English(avoiding technical jargon if
   possible) what you don't understand
  (eg what you expected to happen and what actually happened)
4) Post in plain text not HTML. The latter causes Python
   code to become badly formatted and makes reading it difficult.
5) Don't send attachments, cut 'n paste text into the message.

It looks like a lot but it will help you get better
quality answers much faster.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2016-11-16 Thread Ben Finney
Omari Lamar  writes:

> I am looking for assistance with the python language.

Yes, we offer that here. You need to ask your question in this forum and
volunteers will collaborate to teach you, in public.

This way many other people can also benefit from observing the
discussion.

> Can you send out an eblast asking that if anyone can offer 1 on 1
> assistance via skype to cover the basics that would be greatly
> appreciated.

What rate are you willing to pay for one-on-one real-time interaction?
That is rather less beneficial to the community and quite a drain on one
person's time, so you can expect to pay handsomely for it.

Instead I would recommend you take the opportunity of collaborative
tutoring by public discussion here.

-- 
 \  “I have a large seashell collection, which I keep scattered on |
  `\the beaches all over the world. Maybe you've seen it.” —Steven |
_o__)   Wright |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2016-11-16 Thread Omari Lamar
Good Day,

I am looking for assistance with the python language. Can you send out an
eblast asking that if anyone can offer 1 on 1 assistance via skype to cover
the basics that would be greatly appreciated.
-- 
Omari Lamar
Creating My Future
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2016-10-17 Thread Andrew Koe
Hi,
 Also, you have a typo in your elif path == '2' statement.  It
should be rock = input('Do you want to pick up the rock') with one
equal sign not rock == input ('Do you want to pick up the rock').

-Andrew

On Sat, Oct 15, 2016 at 6:48 PM, Nicholas Hopkins
 wrote:
> Hello
> Please tell me what is wrong with my code and how I can put an if else 
> statement inside of another if else statement
> This is my code:
> path = input('Which path number will you take?')
> if path == '1':
>  print('You took the first path')
> elif path == '2':
>  print('You choose to take the second path')
>  print('You see a rock')
>   rock == input('Do you want to pick up the rock')
>   if rock == 'yes':
>   print('you picked up the rock')
>   else:
>   print('You left the rock')
> elif path == '3':
>  print('You choose to take the third path')
> else:
>  print('You must choose a number between 1 and 3')
>
>
> it comes up with this error
> [cid:image001.png@01D22792.63CCF290]
> Thanks
> Sent from Mail for Windows 10
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2016-10-16 Thread Alex Kleider

On 2016-10-15 15:48, Nicholas Hopkins wrote:

Hello
Please tell me what is wrong with my code and how I can put an if else
statement inside of another if else statement
This is my code:
path = input('Which path number will you take?')
if path == '1':
 print('You took the first path')
elif path == '2':
 print('You choose to take the second path')
 print('You see a rock')
  rock == input('Do you want to pick up the rock')
  if rock == 'yes':
  print('you picked up the rock')
  else:
  print('You left the rock')
elif path == '3':
 print('You choose to take the third path')
else:
 print('You must choose a number between 1 and 3')


it comes up with this error
[cid:image001.png@01D22792.63CCF290]


Can't see your error (text only list) but it's probably due to 
indentation problems.

Why do you have only the first line not indented?
Also check indentation of lines 7, 8 and 10.



Thanks
Sent from Mail for 
Windows 10


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2016-10-16 Thread Alan Gauld via Tutor
On 15/10/16 23:48, Nicholas Hopkins wrote:
> Please tell me what is wrong with my code and how I can put an if else 
> statement 
> inside of another if else statement

You are almost right but...

> This is my code:
> path = input('Which path number will you take?')
> if path == '1':
>  print('You took the first path')
> elif path == '2':
>  print('You choose to take the second path')
>  print('You see a rock')
>   rock == input('Do you want to pick up the rock')

indentation is important in Python and the above line
should line up with the one above it. You should have
gotten an Indentation Error message.

>   if rock == 'yes':
>   print('you picked up the rock')
>   else:
>   print('You left the rock')

And if this clause lined up correctly too then it would
work as you expected.

> elif path == '3':
>  print('You choose to take the third path')
> else:
>  print('You must choose a number between 1 and 3')
> 
> 
> it comes up with this error
> [cid:image001.png@01D22792.63CCF290]

Please include the error in your message. This is a text
only list and attachments tend to get stripped off


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help

2016-10-16 Thread Nicholas Hopkins
Hello
Please tell me what is wrong with my code and how I can put an if else 
statement inside of another if else statement
This is my code:
path = input('Which path number will you take?')
if path == '1':
 print('You took the first path')
elif path == '2':
 print('You choose to take the second path')
 print('You see a rock')
  rock == input('Do you want to pick up the rock')
  if rock == 'yes':
  print('you picked up the rock')
  else:
  print('You left the rock')
elif path == '3':
 print('You choose to take the third path')
else:
 print('You must choose a number between 1 and 3')


it comes up with this error
[cid:image001.png@01D22792.63CCF290]
Thanks
Sent from Mail for Windows 10

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2015-08-24 Thread William
This is in response to a much earlier posting for which I don't have the email

[Tutor] Python help

IDN3 iradn3777 at gmail.com
Thu Aug 13 03:01:12 CEST 2015

Previous message (by thread): [Tutor] revisiting a puzzle about -3**2 vs (-3)**2
Next message (by thread): [Tutor] Python help
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]



To whom it may concern,
I am having a problem solving the below question.  I have used every
resource that I could find to help me, but I'm seeing nothing.  Can someone
out there please help me understand the below question and learn how to
accomplish this task in Python?  I would really appreciate any help that
someone could afford.


*Problem 1:* Write a program that will calculate the problem and stop after
the condition has been met.



a=number of loops (start with zero)

b=a+1

c=a+b



Condition: If c is less than 5, then the loop will continue; else, it will
end.



3.   *Problem 2:*Print a string variable that states the number of loops
required to meet the condition for Problem 1.

My attempt below.  I used a while loop even though the question is saying
IF/THEN/ELSE.  To my knowledge loops in Python have to be while/for.  Also,
it seems like the question is missing some direction, but I could be
wrong.  Thank you for your help.

a = 0
b = a + 1
c = a + b
while (c  5):
print(c)
c = c + 1



Response follows

Yes, I agree the wording of the question is confusing. But I think the
following solution makes sense for it. My solution is close to yours,
with a few differences: .
1) the variable a will count the number of times the loop goes around.
2) variable a has to be incremented inside the while loop
3) both a and c have to be initialized to zero before the loop starts.
4) after the loop ends, print a string with the variable to tell how
many times the loop went

a = 0 #increments with each loop
c = 0

while (c5):
b = a+1
c = a+b
a += 1
print(c)

print(Number of loops until c = 5:, a)


I think that is all that is being asked here. HTH!

-William
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help

2015-08-13 Thread IDN3
To whom it may concern,
I am having a problem solving the below question.  I have used every
resource that I could find to help me, but I'm seeing nothing.  Can someone
out there please help me understand the below question and learn how to
accomplish this task in Python?  I would really appreciate any help that
someone could afford.


*Problem 1:* Write a program that will calculate the problem and stop after
the condition has been met.



a=number of loops (start with zero)

b=a+1

c=a+b



Condition: If c is less than 5, then the loop will continue; else, it will
end.



3.   *Problem 2:*Print a string variable that states the number of loops
required to meet the condition for Problem 1.

My attempt below.  I used a while loop even though the question is saying
IF/THEN/ELSE.  To my knowledge loops in Python have to be while/for.  Also,
it seems like the question is missing some direction, but I could be
wrong.  Thank you for your help.

a = 0
b = a + 1
c = a + b
while (c  5):
print(c)
c = c + 1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2015-08-13 Thread Cameron Simpson

On 13Aug2015 10:34, ALAN GAULD alan.ga...@btinternet.com wrote:

On 13/08/15 02:01, IDN3 wrote:

[...snip...]

Condition: If c is less than 5, then the loop will continue; else, it will
end.



3.   *Problem 2:*Print a string variable that states the number of loops
required to meet the condition for Problem 1.


This is a simple bit of math.
You don't need to run the loop to figure out the answer,
just write an equation.


Maybe so, but for an arbitrarily weird condition running the loop may be the 
way to go. Therefore I would imagine he is being asked to print how many times 
that loop ran. So he should just print that value after the loop finishes (i.e 
outside the loop).



My attempt below.  I used a while loop even though the question is saying
IF/THEN/ELSE.


You obviously did not send the whole question.
I don't see any mention of if/then/else?


Actually, the question's Condition: section is written in exactly those 
terms.



To my knowledge loops in Python have to be while/for.  Also,
it seems like the question is missing some direction, but I could be
wrong.


The way I would read your Cndition: requirement is that it is describing what 
kind of decision must be made every time the loop commences. It is not telling 
you to use Pythons if statement. So just putting the correct condition at the 
top of the while loop is what you want.


Cheers,
Cameron Simpson c...@zip.com.au

If you lie to the compiler, it will get its revenge.- Henry Spencer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2015-08-13 Thread Alan Gauld

On 13/08/15 10:44, Cameron Simpson wrote:


You obviously did not send the whole question.
I don't see any mention of if/then/else?


Actually, the question's Condition: section is written in exactly
those terms.


Oops, so it is. My bad.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2015-08-13 Thread Alan Gauld

On 13/08/15 02:01, IDN3 wrote:

To whom it may concern,
 I am having a problem solving the below question.  I have used every
resource that I could find to help me, but I'm seeing nothing.  Can someone
out there please help me understand the below question and learn how to
accomplish this task in Python?  I would really appreciate any help that
someone could afford.


OK, We won;t give you the solution but we can certainly help you 
understand the question and point you in the right direction.



*Problem 1:* Write a program that will calculate the problem and stop after
the condition has been met.

a=number of loops (start with zero)
b=a+1
c=a+b


Notice that a is the thing that counts the number of loops.
So you need to increment a inside your loop.
b and c are based on a.


Condition: If c is less than 5, then the loop will continue; else, it will
end.




3.   *Problem 2:*Print a string variable that states the number of loops
required to meet the condition for Problem 1.


This is a simple bit of math.
You don't need to run the loop to figure out the answer,
just write an equation.


My attempt below.  I used a while loop even though the question is saying
IF/THEN/ELSE.


You obviously did not send the whole question.
I don't see any mention of if/then/else?


To my knowledge loops in Python have to be while/for.  Also,
it seems like the question is missing some direction, but I could be
wrong.


The two questions are both OK, but i think you missed the bit that said 
a was the variable that counted the number of times round the loop.
This is a little bit unusual since normally your while loop test uses 
the counting variable (ie. a) but in this case it uses c which is
based on a. But it does demonstrate that the while condition can be more 
complex that the basic form.



a = 0
b = a + 1
c = a + b
while (c  5):
 print(c)
 c = c + 1


You need to make a the counter and not c.
You need to recalculate c after changing a.
You need to print the number of loops (a) not c.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python help

2015-07-06 Thread Cary Developer
I am looking for help on getting started with Python.  This link says it
all:

 

http://raleigh.craigslist.org/cpg/5108772711.html

 

Any help (and response to the CL post) would be truly appreciated.  Thanks.

 

-Roger

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2015-07-06 Thread Mark Lawrence

On 06/07/2015 15:24, Cary Developer wrote:

Welcome.


I am looking for help on getting started with Python.


You've come to the right place, that's always a good start.



This link says it all:

http://raleigh.craigslist.org/cpg/5108772711.html

Any help (and response to the CL post) would be truly appreciated.  Thanks.

-Roger


For someone with programming experience try this 
http://www.diveintopython3.net/


Anybody suggesting to you starting with Django before they've learnt 
basic Python needs a really good psychiatrist, although I understand 
that they're rather more expensive in the USA than the UK :)


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2015-07-06 Thread Alan Gauld

On 06/07/15 15:24, Cary Developer wrote:

I am looking for help on getting started with Python.  This link says it
all:

http://raleigh.craigslist.org/cpg/5108772711.html


It would be more helpful to post the content of the query, not
all mail subscribers can access web pages at the time of reading
the mail.


Any help (and response to the CL post) would be truly appreciated.  Thanks.


Since you are experienced in web development and PHP/SQL you should go 
straight to the official Python tutorial.


It will take you through the basics in a few hours - less than a full 
day for sure.


You could then look at the Django tutorial if you want to go down the
web route. (Other frameworks exist - lots of them - but Django is 
powerful, and very popular and has good support from its own community)


Python 3.4 is the preferred version for newbies these days unless
you know that your target framework/toolset only runs on v2

If you have more specific questions ask here...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2015-07-06 Thread Matt Williams
Personally I would start with Python 2.7, and start with simple scripts.

The standard library in Python is very wide, and having a good
understanding of what is already there is very useful.

As to GUI/ Web/ etc. - I think it depends on what you want to do. However,
you will need the basics before then.

You don't say what your background is, but if you've done some programming
before then the basics should be pretty quick.

Once you've done the basics, some more intermediate level stuff is
useful. Personally, I find reading source code useful (there is a tonne on
the PPI). There are some other resources listed here:

https://news.ycombinator.com/item?id=5998750

HTH,
M

On 6 July 2015 at 15:24, Cary Developer carydevelo...@gmail.com wrote:

 I am looking for help on getting started with Python.  This link says it
 all:



 http://raleigh.craigslist.org/cpg/5108772711.html



 Any help (and response to the CL post) would be truly appreciated.  Thanks.



 -Roger



 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2015-07-06 Thread Mark Lawrence

On 06/07/2015 22:09, Matt Williams wrote:

Personally I would start with Python 2.7, and start with simple scripts.



I think it makes much more sense to learn Python 3 and if you need code 
to run on both 2 and 3 take the advice here 
https://docs.python.org/3/howto/pyporting.html


By the way, please don't top post here, in can get irritating trying to 
follow long threads, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2015-06-24 Thread Nirav Patel via Tutor
Hi, my name is Nirav. 
I have a question about my code. I am a student at a university that does 
research using a program called VisIt. We use VisIt to help our learning in 
computational fluid dynamics and using the information, we study the turbulence 
of scramjets. 
One simple thing I am trying to do is using python to call a command that 
processes all the files that exist within the directory by having visit access 
the files. 
I have started to code below, but every time the code is executed, I get an 
error that says, u-name command not found along with an error that says, 
VisIt is not supported by platform. I know my information is hard to follow 
or comprehend, but I really need to find a way to get this code working. 
Thank you in advance!
import osos.environ[PATH]= 
'/Applications/VisIt.app/Contents/Resources/bin/'files = 
os.listdir('/Users/niravpatel/Desktop/Visit /plotfiles')print filesfor file in 
files:    if '.py' in file:        import subprocess        
subprocess.call(['visit', '-nowin', '-cli'])        
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2015-06-24 Thread Alan Gauld

On 24/06/15 20:25, Nirav Patel via Tutor wrote:
 ... research using a program called VisIt.


One simple thing I am trying to do is using python
to call a command that processes all the files that

 exist within the directory by having visit access the files.


I have started to code below, but every time the code

 is executed, I get an error that says,

u-name command not found
along with an error that says,
VisIt is not supported by platform.


Can you post the actual print out from your console in full?
Also can you tell us what 'platform' you are using
 - OS, and VisIT and Python versions


import osos.environ[PATH]= 
'/Applications/VisIt.app/Contents/Resources/bin/'files = 
os.listdir('/Users/niravpatel/Desktop/Visit /plotfiles')print filesfor file in files:
if '.py' in file:import subprocesssubprocess.call(['visit', '-nowin', 
'-cli'])


Please post code in plain text, this is all in one line making it very 
hard to read. I'll try to unscramble it...


 import os
 os.environ[PATH]= '/Applications/VisIt.app/Contents/Resources/bin/'
 files = os.listdir('/Users/niravpatel/Desktop/Visit /plotfiles')
 print files

Looks like Python v2?
I'm not sure why you are setting the PATH environment variable unless 
VisIT reads it? If so you do realize that setting it like this will wipe 
out all the existing entries?

Finally is there supposed to be a space in the last folder name?

 for file in files:
 if '.py' in file:

You are looping over the python files? Is that really what you want?

 import subprocess

Its usual to put all imports at the top of the file in one place.
Not necessary but conventional.

 subprocess.call(['visit', '-nowin', '-cli'])

You are not specifying any input files/paths to visit so you
just repeat the same command over and over.

Do the commands

PATH='/Applications/VisIt.app/Contents/Resources/bin/'
visit -nowin -cli

work at the command line?
Or do you get different error messages?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2015-05-04 Thread Grace Anne St Clair-Bates
I am trying to write a program that uses while and if loops, but my print
statements are not going through and showing up when I run the module. I
have tried numerous things and changed in the code and cannot for the life
of me figure out why it won't print. If someone could help that would be
amazing. Thank you
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2015-05-04 Thread Peter Otten
Grace Anne St Clair-Bates wrote:

 I am trying to write a program that uses while and if loops, but my print
 statements are not going through and showing up when I run the module. I
 have tried numerous things and changed in the code and cannot for the life
 of me figure out why it won't print. If someone could help that would be
 amazing. Thank you

Write a small example script that shows the problem. Post it here so that we 
have something to start the discussion.

Do not attach the script to your mail, put it into the body as plain text. 
Only then everyone can see your code.

Thank you.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2015-05-04 Thread Alan Gauld

On 04/05/15 06:00, Grace Anne St Clair-Bates wrote:

I am trying to write a program that uses while and if loops, but my print
statements are not going through and showing up when I run the module. I
have tried numerous things and changed in the code and cannot for the life
of me figure out why it won't print. If someone could help that would be
amazing. Thank you


To help you would need to show us the code.
We are not mind readers.

Also post any error messages you get, they
are full of useful information once you
learn how to read them.

Finally, please tell us which Python version you are using,
which OS and which tutorial or book you are using.

With that information available we can try to help.

But note: if *statements* are not *loops*.
*loops* are bits of code that repeat zero or more times.
*if statements* are bits of code that may or may not
execute depending on some test result.

In programming it is very important to be precise
in your language. Otherwise we all get very confused
about what you mean.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2015-04-14 Thread Janelle Harb
Hello! I have a Mac and idle refuses to quit no matter what I try to do.  What 
should I do?
Thank you!
-Janelle
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2015-04-14 Thread Alan Gauld

On 14/04/15 02:39, Janelle Harb wrote:

Hello! I have a Mac and idle refuses to quit no matter what I try to do.  What 
should I do?


You  can start by giving us some specific examples of things you did 
that didn't work.


Starting with the obvious:
1) Did you click the little close icon?
2) Did you use the Quit option in the menus?
3) Did you try a Force Quit?
4) Did you run kill from the terminal?
5) Did you try rebooting?
6) Did you hit it with a club hammer?

Without any idea of what you did we can't suggest anything
specific. It might also help if you tell us which OS version,
which Python version, and whether this has always been
the case or if its something that only happened recently.
If the latter, what were you doing with IDLE immediately
before the problem arose?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help with Program

2015-02-16 Thread Steven D'Aprano
Hi Tina, or Taylor, welcome!

Sorry but your email From header says your name is Tina and your 
signature says Taylor so I'm not sure which name you prefer.


On Sun, Feb 15, 2015 at 07:26:35PM -0600, Tina Figz wrote:
 I'm having a problem with my program and I'm not sure how to correct it
 (I'm in an intro programming class).
 
 My program is supposed two numbers and count the number of carry
 operations.

Let's start by working it out using pencil and paper. Write down two 
numbers, lined up on the right:

472837
 29152


for example. Let's go through and check for carries:

Number of carries so far: 0
7 and 2 = 9, no carry.
3 and 5 = 8, no carry.
8 and 1 = 9, no carry
2 and 9 = 11, carry the 1. Add one to the number of carries.
7 and 2, plus the 1 we carried, = 10, carry the 1. So add one to number 
of carries.
4, plus the 1 we carried, = 5, no carry.

So the number of carries is two.

The process is to take the digits of each number, starting from the 
right-hand end, in pairs. If you run out of digits for one number before 
the other, use 0. Add the two digits together, plus any carry digit from 
before, and if the result is larger than 9, there's a carry.

We start with the number of carries equal to 0, and add 1 to that *only* 
if adding the pair of digits is larger than 9.

Let's see what you have:

[snip part of the code]
 eq = int_lastn1 + int_lastn2
 carry = 0
 while eq = 10 and carry  len(sn1) and carry  len(sn2):
 num1 += 1
 num2 += 1
 carry += 1

You start on the right track: you check whether the last two digits add 
to more than 9. But, you never check the next two digits, or the two 
after that. You calculate eq (which is not a good name, by the way) 
once, outside the loop, but never calculate it again with any additional 
digits.

Instead, you add 1 to carry *every single time*, regardless of the 
digits (apart from the first).

Fun fact: (well, not that fun) you have to repeat the calculation each 
time through the loop, otherwise you're just using the same result over 
and over again. Example:

py my_string = 12345
py position = -1
py total = int(my_string[position]) + 1000
py while position  -len(my_string):
... print(total)
... position = position - 1
...
1005
1005
1005
1005


The total never changes, because we never re-calculate it. Instead:

py my_string = 12345
py position = -1
py while position  -len(my_string):
... total = int(my_string[position]) + 1000
... print(total)
... position = position - 1
...
1005
1004
1003
1002


Does that help you see why your code counts the wrong number of carries, 
and help you fix it?



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help with Program

2015-02-16 Thread Mark Lawrence

On 16/02/2015 08:24, Alan Gauld wrote:

On 16/02/15 01:26, Tina Figz wrote:

I'm having a problem with my program and I'm not sure how to correct it
(I'm in an intro programming class).

My program is supposed two numbers and count the number of carry
operations.

This is what I have:

n1 = int(raw_input('Number #1: '))
n2 = int(raw_input('Number #2: '))
add = n1 + n2

  print ' '
  print n1, '+', n2, '=', add

Down to here everything is ok and you get the sum of the two numbers



sn1 = str(n1)
sn2 = str(n2)
num1 = 1
num2 = 1
num1 == num2


This line doesn't do anything.


last_n1 = sn1[-num1]
last_n2 = sn2[-num2]
int_lastn1 = int(last_n1)
int_lastn2 = int(last_n2)
eq = int_lastn1 + int_lastn2
carry = 0


Before entering the loop you have (for your example)
sn1 = '239', sn2 = '123' num1 = 1, num2 = 1
last_n1 = '9',last_n2 = '3', int_lastn1 = 9, int_lastn2 = 3
eq = 12
carry = 0


while eq = 10 and carry  len(sn1) and carry  len(sn2):
 num1 += 1
 num2 += 1
 carry += 1


Your loop only changes num1, num2 and carry.
But only carry is tested in the loop condition.
So in effect you just keep adding 1 to carry
until it is  then len(sn1 or len(sn2), ie 3.

You are not changing anything else, so you are effectively
just counting the number of characters in your shortest
number.


When I input 239  123 as my two numbers it equals 362, which is correct.
But it says I have 3 carries, when the answer should be 1 carry
operation.


You need to completely redesign your algorithm.
Try writing it out using pen and paper to figure
out how you would do it manually.



I'd start this exercise at line 1 and work right the way through the 
code, e.g. why bother doing all the work to get sn1 and sn2?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help with Program

2015-02-16 Thread Alan Gauld

On 16/02/15 01:26, Tina Figz wrote:

I'm having a problem with my program and I'm not sure how to correct it
(I'm in an intro programming class).

My program is supposed two numbers and count the number of carry
operations.

This is what I have:

n1 = int(raw_input('Number #1: '))
n2 = int(raw_input('Number #2: '))
add = n1 + n2

 print ' '
 print n1, '+', n2, '=', add

Down to here everything is ok and you get the sum of the two numbers



sn1 = str(n1)
sn2 = str(n2)
num1 = 1
num2 = 1
num1 == num2


This line doesn't do anything.


last_n1 = sn1[-num1]
last_n2 = sn2[-num2]
int_lastn1 = int(last_n1)
int_lastn2 = int(last_n2)
eq = int_lastn1 + int_lastn2
carry = 0


Before entering the loop you have (for your example)
sn1 = '239', sn2 = '123' num1 = 1, num2 = 1
last_n1 = '9',last_n2 = '3', int_lastn1 = 9, int_lastn2 = 3
eq = 12
carry = 0


while eq = 10 and carry  len(sn1) and carry  len(sn2):
 num1 += 1
 num2 += 1
 carry += 1


Your loop only changes num1, num2 and carry.
But only carry is tested in the loop condition.
So in effect you just keep adding 1 to carry
until it is  then len(sn1 or len(sn2), ie 3.

You are not changing anything else, so you are effectively
just counting the number of characters in your shortest
number.


When I input 239  123 as my two numbers it equals 362, which is correct.
But it says I have 3 carries, when the answer should be 1 carry operation.


You need to completely redesign your algorithm.
Try writing it out using pen and paper to figure
out how you would do it manually.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help with Program

2015-02-15 Thread Tina Figz
I'm having a problem with my program and I'm not sure how to correct it
(I'm in an intro programming class).

My program is supposed two numbers and count the number of carry
operations.

This is what I have:

n1 = int(raw_input('Number #1: '))
n2 = int(raw_input('Number #2: '))
add = n1 + n2
print ' '
print n1, '+', n2, '=', add
print ' '
sn1 = str(n1)
sn2 = str(n2)
num1 = 1
num2 = 1
num1 == num2
last_n1 = sn1[-num1]
last_n2 = sn2[-num2]
int_lastn1 = int(last_n1)
int_lastn2 = int(last_n2)
eq = int_lastn1 + int_lastn2
carry = 0
while eq = 10 and carry  len(sn1) and carry  len(sn2):
num1 += 1
num2 += 1
carry += 1
print 'Number of carries:', carry

When I input 239  123 as my two numbers it equals 362, which is correct.
But it says I have 3 carries, when the answer should be 1 carry operation.

I'm not sure how to correct this error.

Thanks,

Taylor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help

2014-11-03 Thread Juwel Williams
Good Day,

I am in a python class at my school. I am very confused, he gives us 
assignments but I am not sure how to attempt it. I am confused about tuples, 
lists and dictionaries. Now he has moved on to class and modules. Can you 
assist me please.

He has given us a module to go by. 

It says define a new variable called MOVES that contains a dictionary.
- I assume this means to create an empty dictionary to the variable called 
moves.
MOVES = { }

Then it says, “As keys, use the move variable defined in the pokemon module” 
- Is keys what we use in the parameters? 


Thank you,

Juwel
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2014-11-03 Thread Alan Gauld

On 03/11/14 20:26, Juwel Williams wrote:


I am confused about tuples, lists and dictionaries.


The more specific your question the easier it is for us to answer.
What exactly is confusing you about them?
What they are? How to use them? The syntax?


Now he has moved on to class and modules. Can you assist me please.


Lets stick with lists, tuples and dictionaries for now.

You could try reading through the Raw Materials topic in my
tutorial (see .sig below) which discusses all three - and much
more besides.



He has given us a module to go by.

It says define a new variable called MOVES that contains a dictionary.
- I assume this means to create an empty dictionary to the variable called 
moves.
MOVES = { }


I assume so too, the terminology is wrong for Python but accurate
for most languages. Python variables dont store data inside themselves, 
they are only names referring to data values(objects).


But I think you are right, he means create a variable that refers to an 
empty dictionary.



Then it says, “As keys, use the move variable defined in the pokemon module”
- Is keys what we use in the parameters?


Recall that dictionaries consist of key-value pairs. You access
a value by passing the dictionary a key.

It seems that you have access to a Python module called pokemon?
Within that module is a variable called move. Without knowing what that 
variable looks like its hard for me to give you any further advise, but 
somehow you are expected to map the move values to dictionary keys...


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2014-10-20 Thread Taylor Ruzgys
Hi, I was wondering if you could help me with an assignment that I'm doing 
involving Python?  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2014-10-20 Thread Alan Gauld

On 20/10/14 03:56, Taylor Ruzgys wrote:

Hi, I was wondering if you could help me with an assignment that I'm
doing involving Python?


Yes, we can help you do it. We won't do it for you.

You need to tell us what the assignment is, how you have tried
to solve it, including any code you've written. Explain where
and how you are stuck.

Include the full text of any error messages.
Tell us the Python version and OS you use.
Tell us if you are using any non standard libraries/modules


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2014-04-09 Thread Adam Grierson
Hi

 

I'm using 3D climate data (ending in “.nc”). The cube contains time, longitude 
and latitude. I would like to look at the average output over the last 20 
years. The time field spans back hundreds of years and I only know how to 
collapse the entire field into a mean value. How can I tell python to collapse 
just the last 20 years into a mean value? 

 

Thank you

Adam___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2014-04-09 Thread Alan Gauld

On 09/04/14 20:59, Adam Grierson wrote:


I'm using 3D climate data (ending in “.nc”). The cube contains time,
longitude and latitude. I would like to look at the average output over
the last 20 years. The time field spans back hundreds of years and I
only know how to collapse the entire field into a mean value. How can I
tell python to collapse just the last 20 years into a mean value?


This group is for teaching the fundamentals of the Python language and 
its standard library. You probably can solve this using standard Python 
but I suspect there will be more specific libraries around that you can 
install that will help with this problem. Those libraries will likely be 
a better place to ask.


That having been said, if you want a pure Puython solution we can try to 
help, but we need a lot more detail about what the data looks like and 
what exactly you expect out. Your description is a bit vague and while I 
might be able to find out what you mean by Googling a bit, I'm not that 
keen to spend my time that way. The more you help us the more we can 
help you...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2014-04-09 Thread Chris Calloway

On 4/9/2014 3:59 PM, Adam Grierson wrote:

I'm using 3D climate data (ending in “.nc”). The cube contains time,
longitude and latitude. I would like to look at the average output over
the last 20 years. The time field spans back hundreds of years and I
only know how to collapse the entire field into a mean value. How can I
tell python to collapse just the last 20 years into a mean value?


An .nc file extension is NetCDF. NetCDF can be served by a DAP server. 
A DAP server can be sent a DAP request by a Python DAP client to drill 
for results confined to particular variables, a geographic bounding box, 
and a stop and start timestamp. See:


http://pydap.org

Or you can simply subset the desired subarray of NetCDF data using SciPy:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.netcdf.netcdf_file.html

Here's a tutorial:

snowball.millersville.edu/~adecaria/ESCI386P/esci386-lesson14-Reading-NetCDF-files.pdf

--
Sincerely,

Chris Calloway http://nccoos.org/Members/cbc
office: 3313 Venable Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help

2014-02-28 Thread Tone Lite
Hello,

I am having trouble coming up with a solution to this exercise and any help
would be appreciated, thanks! I have attached the code below.



'''exercise to complete and test this function'''

def joinStrings(stringList):
'''Join all the strings in stringList into one string,
and return the result, NOT printing it. For example:

 s = joinStrings(['very', 'hot', 'day']) # returns string
 print(s)
veryhotday
'''
# finish the code for this function



def main():
print(joinStrings(['very', 'hot', 'day']))
print(joinStrings(['this', 'is', 'it']))
print(joinStrings(['1', '2', '3', '4', '5']))

main()
'''exercise to complete and test this function'''

def joinStrings(stringList):
'''Join all the strings in stringList into one string,
and return the result, NOT printing it. For example:

 s = joinStrings(['very', 'hot', 'day']) # returns string
 print(s) 
veryhotday
'''
# finish the code for this function



def main():
print(joinStrings(['very', 'hot', 'day']))
print(joinStrings(['this', 'is', 'it']))
print(joinStrings(['1', '2', '3', '4', '5']))

main()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2014-02-28 Thread Ben Finney
Tone Lite tonelitebe...@gmail.com writes:

 I am having trouble coming up with a solution to this exercise and any
 help would be appreciated, thanks! I have attached the code below.

The code you present appears to be the exercise. Are you asking for
someone to write the solution for you? That isn't what we do here. We'll
help you, but that doesn't mean we'll do your work for you.

Please show us what you've tried, describe what it should be doing, and
what is happening instead. If there is an error, please also show the
complete error output.

-- 
 \  “He who allows oppression, shares the crime.” —Erasmus Darwin, |
  `\ grandfather of Charles Darwin |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2014-02-28 Thread James Chapman
The answer lies in this page:
http://docs.python.org/3.3/library/stdtypes.html#string-methods

--
James


On 28 February 2014 11:44, James Chapman ja...@uplinkzero.com wrote:
 The answer lies in this page:
 http://docs.python.org/3.3/library/stdtypes.html#string-methods


 --
 James


 On 28 February 2014 08:15, Ben Finney ben+pyt...@benfinney.id.au wrote:
 Tone Lite tonelitebe...@gmail.com writes:

 I am having trouble coming up with a solution to this exercise and any
 help would be appreciated, thanks! I have attached the code below.

 The code you present appears to be the exercise. Are you asking for
 someone to write the solution for you? That isn't what we do here. We'll
 help you, but that doesn't mean we'll do your work for you.

 Please show us what you've tried, describe what it should be doing, and
 what is happening instead. If there is an error, please also show the
 complete error output.

 --
  \  “He who allows oppression, shares the crime.” —Erasmus Darwin, |
   `\ grandfather of Charles Darwin |
 _o__)  |
 Ben Finney

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-Help] Please help replace Long place-names with short place-names in many files with Python

2013-09-01 Thread bob gailer
Welcome. We are a few volunteers who like to help you when you have 
tried something and are stuck.


It is best to post to just one email list. Most of us monitor tutor and 
help.


We don't write programs for you. Some of us would be happy to do that 
for a consulting fee.


Why Python?

What other programming experience do you have?

Do you know the basics:
  getting a list of filenames in a directory?
  loops?
  opening and reading / writing files?
  searching for strings in larger strings?
  replacing strings?

OMG I just wrote the outline of your program!

Try writing a program to do some of the above then come back with questions.

Start with something simple - process just one file.

Or hire me as a consultant and I will write it for you.

[snip]

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-Help] Instancing class issue

2013-08-15 Thread Dino Bektešević
Hello,


The name of the variable doesn't matter, that's still what it does; you can
 think of it as encapsulating any other keyword arguments.

  def foo(bar, **kwargs):
 ... print(bar: %s % (bar,))
 ... print(kwargs: %r % (kwargs,))
 ...
  foo(bar, baz=qux, wibble=wobble)
 bar: bar
 kwargs: {'baz': 'qux', 'wibble': 'wobble'}



Yeah so much I figured, same way self could be me, but what kind of
__init__ function is that that doesn't even know how many arguments it
takes, at least it should have the mandatory arguments to satisfy the
Parent __init__ function which is object but I don't even see
object.__init__(self,
**kwargs) in sdsspy's __init__ (or **keys whatever you prefer) what are
even the keyword arguments needed for instancing object. Isn't object like
THE most abstract class that becomes anything? How do I even go about
trying to instance this? (and since it calls on some printed error
obviously written somewhere in the SDSSPY how do I reach it so I'd know
what to do?)

many thanks to responders,
Dino Bektešević

2013/8/12 Chris Down ch...@chrisdown.name

 Hi Dino,

 On 2013-08-12 20:32, Dino Bektešević wrote:
  def __init__(self, **keys):
  from . import util
 
  self.keys=keys
  self.load()
 
  where I don't understand what **keys mean, I've only seen that as
 **kwargs
  meaning other key words and arguments in examples.

 The name of the variable doesn't matter, that's still what it does; you can
 think of it as encapsulating any other keyword arguments.

  def foo(bar, **kwargs):
 ... print(bar: %s % (bar,))
 ... print(kwargs: %r % (kwargs,))
 ...
  foo(bar, baz=qux, wibble=wobble)
 bar: bar
 kwargs: {'baz': 'qux', 'wibble': 'wobble'}


  When I try to instance
  Astrom class by:
  new=Astrom()
  I receive a following error:

 Sorry, no idea about this bit, I've never used sdsspy. est of luck sorting
 this
 out.

 Chris

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-Help] Instancing class issue

2013-08-12 Thread Chris Down
Hi Dino,

On 2013-08-12 20:32, Dino Bektešević wrote:
 def __init__(self, **keys):
 from . import util

 self.keys=keys
 self.load()

 where I don't understand what **keys mean, I've only seen that as **kwargs
 meaning other key words and arguments in examples.

The name of the variable doesn't matter, that's still what it does; you can
think of it as encapsulating any other keyword arguments.

 def foo(bar, **kwargs):
... print(bar: %s % (bar,))
... print(kwargs: %r % (kwargs,))
...
 foo(bar, baz=qux, wibble=wobble)
bar: bar
kwargs: {'baz': 'qux', 'wibble': 'wobble'}


 When I try to instance
 Astrom class by:
 new=Astrom()
 I receive a following error:

Sorry, no idea about this bit, I've never used sdsspy. est of luck sorting this
out.

Chris


pgpR9GydIB2YX.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help!!

2013-04-02 Thread David Mitchell
Hi!
How do I go through a text file, finding specific words/numbers/phrases and 
edit them to say different things? I do not want to edit the text file, I would 
rather open and read from the text file and write to a new file. 
I do NOT want to know how to replace a specific word with another every time it 
appears. There are some OFF 's that i would like to change to ON 's and 
some that I would like to change to OPEN for example. 
I am doing all this in Linux Fedora with gedit. It is a project assigned to me 
from my boss and I'm just a co-op student so I could really use the help. 
Any help would be greatly appreciated!!
Thanks,
David ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help!!

2013-04-02 Thread taserian
On Tue, Apr 2, 2013 at 12:49 PM, David Mitchell d_mitchel...@hotmail.comwrote:

 Hi!

 How do I go through a text file, finding specific words/numbers/phrases
 and edit them to say different things? I do not want to edit the text file,
 I would rather open and read from the text file and write to a new file.

 I do NOT want to know how to replace a specific word with another every
 time it appears. There are some OFF 's that i would like to change to
 ON 's and some that I would like to change to OPEN for example.


How would you know which ones to change to ON and which ones to change to
OPEN? Additionally, how would you describe those conditions in Python?


Antonio Rodriguez
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help!!

2013-04-02 Thread Bod Soutar
On 2 April 2013 17:49, David Mitchell d_mitchel...@hotmail.com wrote:
 Hi!

 How do I go through a text file, finding specific words/numbers/phrases and
 edit them to say different things? I do not want to edit the text file, I
 would rather open and read from the text file and write to a new file.

 I do NOT want to know how to replace a specific word with another every time
 it appears. There are some OFF 's that i would like to change to ON 's
 and some that I would like to change to OPEN for example.

 I am doing all this in Linux Fedora with gedit. It is a project assigned to
 me from my boss and I'm just a co-op student so I could really use the help.

 Any help would be greatly appreciated!!

 Thanks,

 David

Can you give us some idea of your skill level, and perhaps some code
that you've already tried?
Your general approach will be something like

open read_file
open write_file
read read_file into a list
close read_file
iterate over the list
if you find a line you want to change
make the change and write to write_file
else
write to write_file

close write_file

HTH,
Bodsda
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help!!

2013-04-02 Thread Elegbede Muhammed Oladipupo

What exactly do you know how to do?

Can you read files?
Can you replace words?

This way, I can know how to help. 
What is hard for me to help with is the fact that you are planning to replace 
the same word with two different words depending on location e.g when you said 
you want to change off to either on or open. 

Let's see what you can do or have done, then help should be on the way. 

Regards. Regards. /div
Sent from my BlackBerry®  PORSCHE® DESIGN wireless handheld from Glo Mobile.

-Original Message-
From: David Mitchell d_mitchel...@hotmail.com
Sender: Tutor tutor-bounces+dipo.elegbede=dipoelegbede@python.orgDate: 
Tue, 2 Apr 2013 12:49:32 
To: tutor@python.orgtutor@python.org
Subject: [Tutor] Python help!!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python help!

2013-02-09 Thread Ghadir Ghasemi
Hi guys can you tell me what is wrong with the second part of this code(elif 
choice == '2'). When I type something other than 0-255, it correctly asks again 
for an input but when I enter a number from 0-255 it does nothing :

def show_menu():
 print(===)
 print(1-binary to denary)
 print(2-denary to binary)
 print(3-exit)
 print(===)


while True:
show_menu()

choice = input(please enter an option: )

if choice == '1':
binary = input(Please enter a binary number: )
denary = 0
place_value = 1

for i in binary [::-1]:
denary += place_value * int(i)
place_value *= 2

print(The result is,denary)
   

elif choice == '2':
 denary2 = int(input(Please enter a denary number: ))
 remainder = ''
 while denary2 not in range(0,256):
 denary2 = int(input(Please enter a denary number: ))
 continue
 while denary2 in range(0,256):
 
remainder = str(denary2 % 2) + remainder
denary2 = 1
 print(The result is,remainder)

   
 

elif choice == '3':
 break


elif choice not in '1' or '2' or '3':
print(Invalid input-try again!)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help!

2013-02-09 Thread Peter Otten
Ghadir Ghasemi wrote:

 Hi guys can you tell me what is wrong with the second part of this
 code(elif choice == '2'). When I type something other than 0-255, it
 correctly asks again for an input but when I enter a number from 0-255 it
 does nothing :

It doesn't do nothing, it keeps running the while loop. Add a print() call

 elif choice == '2':
  denary2 = int(input(Please enter a denary number: ))
  remainder = ''
  while denary2 not in range(0,256):
  denary2 = int(input(Please enter a denary number: ))
  continue
  while denary2 in range(0,256):

  print(XXX denary2 =,  denary2)
  
 remainder = str(denary2 % 2) + remainder
 denary2 = 1
  print(The result is,remainder)

to see what's happening.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help!

2013-02-09 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
I have altered the program to run on Python 2.7.3
Perhaps it will run on Python 3 with small/or no alterations.

def show_menu():
 print(===)
 print(1-binary to denary)
 print(2-denary to binary)
 print(3-exit)
 print(===)


while True:
show_menu()

choice = raw_input(please enter an option: )

if choice == '1':
binary = raw_input(Please enter a binary number: )
denary = 0
place_value = 1

for i in binary [::-1]:
denary += place_value * int(i)
place_value *= 2

print(The result is,denary)


elif choice == '2':
 denary2 = int(raw_input(Please enter a denary number: ))
 remainder = ''
 if denary2 not in range(0,256):
 denary2 = int(input(Please enter a denary number: ))
 continue
 while denary2  0:
remainder = str(denary2 % 2) + remainder
denary2 /= 2
 print(The result is,remainder)




elif choice == '3': break


elif choice == '1' or choice == '2' or choice == '3':
print(Invalid input-try again!)



On Sun, Feb 10, 2013 at 12:50 AM, Peter Otten __pete...@web.de wrote:

 Ghadir Ghasemi wrote:

  Hi guys can you tell me what is wrong with the second part of this
  code(elif choice == '2'). When I type something other than 0-255, it
  correctly asks again for an input but when I enter a number from 0-255 it
  does nothing :

 It doesn't do nothing, it keeps running the while loop. Add a print() call

  elif choice == '2':
   denary2 = int(input(Please enter a denary number: ))
   remainder = ''
   while denary2 not in range(0,256):
   denary2 = int(input(Please enter a denary number: ))
   continue
   while denary2 in range(0,256):

   print(XXX denary2 =,  denary2)

  remainder = str(denary2 % 2) + remainder
  denary2 = 1
   print(The result is,remainder)

 to see what's happening.


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
regards,
Sarma.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help!

2013-02-09 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
Remove also 'continue' statement under the 'if denary2 not in
range(0,256)' clause.


On Sun, Feb 10, 2013 at 7:06 AM, D.V.N.Sarma డి.వి.ఎన్.శర్మ 
dvnsa...@gmail.com wrote:

 I have altered the program to run on Python 2.7.3
 Perhaps it will run on Python 3 with small/or no alterations.

 def show_menu():
  print(===)
  print(1-binary to denary)
  print(2-denary to binary)
  print(3-exit)
  print(===)


 while True:
 show_menu()

 choice = raw_input(please enter an option: )

 if choice == '1':
 binary = raw_input(Please enter a binary number: )
 denary = 0
 place_value = 1

 for i in binary [::-1]:
 denary += place_value * int(i)
 place_value *= 2

 print(The result is,denary)


 elif choice == '2':
  denary2 = int(raw_input(Please enter a denary number: ))
  remainder = ''
  if denary2 not in range(0,256):
  denary2 = int(input(Please enter a denary number: ))
  continue
  while denary2  0:
 remainder = str(denary2 % 2) + remainder
 denary2 /= 2
  print(The result is,remainder)




 elif choice == '3': break


 elif choice == '1' or choice == '2' or choice == '3':
 print(Invalid input-try again!)



 On Sun, Feb 10, 2013 at 12:50 AM, Peter Otten __pete...@web.de wrote:

 Ghadir Ghasemi wrote:

  Hi guys can you tell me what is wrong with the second part of this
  code(elif choice == '2'). When I type something other than 0-255, it
  correctly asks again for an input but when I enter a number from 0-255
 it
  does nothing :

 It doesn't do nothing, it keeps running the while loop. Add a print() call

  elif choice == '2':
   denary2 = int(input(Please enter a denary number: ))
   remainder = ''
   while denary2 not in range(0,256):
   denary2 = int(input(Please enter a denary number: ))
   continue
   while denary2 in range(0,256):

   print(XXX denary2 =,  denary2)

  remainder = str(denary2 % 2) + remainder
  denary2 = 1
   print(The result is,remainder)

 to see what's happening.


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




 --
 regards,
 Sarma.




-- 
regards,
Sarma.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2013-01-26 Thread wrw
On Jan 23, 2013, at 4:37 PM, Grady Trexler grady...@gmail.com wrote:

 
 Below is my code.  I am using python 2.4 It tells me I have a syntax error.  
 Please help!  (I think the first twenty lines have what you would be looking 
 for.  After that it just repeats itself.)
 #scenario maker
 #created by: Grady Trexler
 #started on 1/3/13
 #last update: 1/3/13
 
 def rungame()
   guyone = raw_input(Please enter a name:)
 

[megabyte]


   print %s: EVERYTHING % (guytwo)
   print %s pushed passed %s and ran away.  The two never saw 
 eachother again. % (guytwo, guyone)
 rungame()
 -- 
 --T-rexmix
 Check out my website-
 www.thegradypage.weebly.com 
 It has new blog posts all the time!
 Fight against Gandalf. Like a Balrog. 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


In the future, please also show us the error and the traceback so we don't have 
to read through your whole code looking for lints.


  File text.py, line 1
def rungame()
 ^
SyntaxError: invalid syntax

You forgot the colon after the closing ) in the def statement.

-Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2013-01-26 Thread Dave Angel

On 01/23/2013 04:37 PM, Grady Trexler wrote:

Below is my code.  I am using python 2.4 It tells me I have a syntax error.


I don't see any such thing.  Plesae include the traceback, which will 
indicate WHERE you have a syntax error.  And if you look yourself, 
you'll probably spot it, since it's usually either in the line specified 
or the one right before it.


Also, please use text mail.  By using html, you have killed the 
indentation that you presumably had in your original.  If you didn't 
have it in your original, then that's your second syntax error.


All right, I gave up and tried pasting your misformed code into a text 
editor.  Looks like you have a problem on the very first non-comment 
line:no colon on the def line




  Please help!  (I think the first twenty lines have what you would be
looking for.  After that it just repeats itself.)
#scenario maker
#created by: Grady Trexler
#started on 1/3/13
#last update: 1/3/13

def rungame()
guyone = raw_input(Please enter a name:)

guytwo = raw_input(Please enter a name:)


snip

Also please pick a better topic than  Python Help.  Nearly every new 
thread here is asking for help with Python, so how does yours stand out? 
 Even syntax error would be a better one.




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help?

2012-10-01 Thread c smith
It is hard to see things like images and attachments. I think purely html
is preferred, but i would have to look over 'the list rules' again.
You should look into dictionaries as the structure to hold your info.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help?

2012-10-01 Thread Dave Angel
On 10/01/2012 08:16 PM, c smith wrote:
 It is hard to see things like images and attachments. I think purely html
 is preferred, but i would have to look over 'the list rules' again.

Since this is a text mailing-list, it's text messages that are
preferred.  html messages frequently trash indentation, which can be
fatal to a python source excerpt.  And many people cannot see
attachments at all, while others would simply skip any messages that
require looking at attachments.

 You should look into dictionaries as the structure to hold your info.



-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help?

2012-10-01 Thread Dave Angel
On 09/30/2012 02:02 AM, patrick Howard wrote:
 I have to write a program that takes an input file, with students names and 
 various grades.
 My vindictive teacher also added grades that are not supposed to count, so I 
 need to pick the grades that are 'HM1-4; not HW, or TEST or anything else.
 Then when these are listed in order with that persons name, sort the list 
 alphabetically. I know that this is '.sort;
 But, how do I get it to sort only names, AND keep the right grades with them. 
 Below is a list of parameters… Can you help me please?



What part are you stuck on? It's hard to give advice when we don't know
what part of the assignment matters. First question is what language are
you to write this in, and on what OS. Assuming it's Python, then what's
the version?

I'm a little surprised you call the teacher vindictive. Bad data is
quite common in the real world. And in the real world, I'd be writing a
separate program to cleanse the data before processing.

Anyway, first you need to be able to open the specified file and read
and parse the text lines into some form of data structure.

Second you manipulate that structure, so that the output can be produced
in a straightforward manner.

Third, you produce the output, which now should be pretty straightforward.

Write them as three (at least) separate functions, and you can debug
them separately. Much easier than trying to make it a monolith which
either works or is hopeless.

So the first question is what kind of structure can hold all that data.
I have no idea what level of Python you've attained, but I'll guess you
don't know how to write your own classes or generators. So you have to
build the structures from whatever's in the standard library.

Outermost structure is a list, one per student. Each item of the list is
a defaultdict, keyed by name, and by the various HMn fields. Values of
each of those dict items are floats.

-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help?

2012-10-01 Thread Dave Angel
On 10/01/2012 09:44 PM, Dave Angel wrote:
 On 09/30/2012 02:02 AM, patrick Howard wrote:
 I have to write a program that takes an input file, with students names and 
 various grades.
 My vindictive teacher also added grades that are not supposed to count, so I 
 need to pick the grades that are 'HM1-4; not HW, or TEST or anything else.
 Then when these are listed in order with that persons name, sort the list 
 alphabetically. I know that this is '.sort;
 But, how do I get it to sort only names, AND keep the right grades with 
 them. 

Use a tuple of  (name, grades)   where the name is a string, and the
grades are in a dict or defaultdict.  When sorting a list of tuples, the
sort will work only on the first element of each tuple, unless there's a
tie.  Checking for duplicate student names is one of those things that
gets separately verified, before even running your code.

 Below is a list of parameters… Can you help me please?


 What part are you stuck on? It's hard to give advice when we don't know
 what part of the assignment matters. First question is what language are
 you to write this in, and on what OS. Assuming it's Python, then what's
 the version?

 I'm a little surprised you call the teacher vindictive. Bad data is
 quite common in the real world. And in the real world, I'd be writing a
 separate program to cleanse the data before processing.

 Anyway, first you need to be able to open the specified file and read
 and parse the text lines into some form of data structure.

 Second you manipulate that structure, so that the output can be produced
 in a straightforward manner.

 Third, you produce the output, which now should be pretty straightforward.

 Write them as three (at least) separate functions, and you can debug
 them separately. Much easier than trying to make it a monolith which
 either works or is hopeless.

 So the first question is what kind of structure can hold all that data.
 I have no idea what level of Python you've attained, but I'll guess you
 don't know how to write your own classes or generators. So you have to
 build the structures from whatever's in the standard library.

 Outermost structure is a list, one per student. Each item of the list is
 a defaultdict, keyed by name, and by the various HMn fields. Values of
 each of those dict items are floats.

One simplification, so you won't need a confusing key function, is to
make each item of the list a tuple, student-name string followed by
defaultdict.  By not putting the name inside the dict, sort of the list
will get the order right by default.  In particular, when sorting a list
of tuples, it uses the first item of each tuple as a primary key.

Recapping:
A list of tuples, one tuple per line.  First item of the tuple is the
studentname for that line. Other item of the tuple is a defaultdict
keyed by such strings as HM1, HM2, ...

Now, write some code, and when you get stuck, show us what you have, how
you tested it, and what went wrong.

-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help

2012-09-15 Thread Daniel Hulse
Hi. I am trying to solve a problem and I'm stuck. The problem is something like 
as x goes up by 1, y goes up by the previous value times 2. I have no idea 
where to start. So lets say x = 10 and y=5, when x=11, why would be equal to  
10.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help

2012-09-15 Thread Joel Goldstick
On Sat, Sep 15, 2012 at 11:21 AM, Daniel Hulse dhuls...@gmail.com wrote:
 Hi. I am trying to solve a problem and I'm stuck. The problem is something 
 like as x goes up by 1, y goes up by the previous value times 2. I have no 
 idea where to start. So lets say x = 10 and y=5, when x=11, why would be 
 equal to  10.


Your question is really one of simple algebra

This looks like homework.  You should explain your problem more
completely, and show any code you have tried to solve your problem
-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-Help] What is lambdas in Python??

2011-12-27 Thread bob gailer

On 12/27/2011 8:36 PM, Hitesh Kumar wrote:
I really don't get it. What is lambda? I keep seeing it and I couldn't 
understand anything online about it.


lambda
   An anonymous inline function consisting of a single /expression/
   #term-expression which is evaluated when the function is called.
   The syntax to create a lambda function is lambda [arguments]: expression

It is a way to create a simple anonymous function.

func = lambda x, y : x + y

is the equivalent of

def func(x, y):
return x = y

Handy when the function returns an expression (no compound statements) 
and does not need a name, e.g.

map(lambda x, y : x + y,  (1,2,3), (4,5,6))

OK now you wonder what is map so:

map(/function/, /iterable/, /.../)
   Apply /function/ to every item of /iterable/ and return a list of
   the results. If additional /iterable/ arguments are passed,
   /function/ must take that many arguments and is applied to the items
   from all iterables in parallel. If one iterable is shorter than
   another it is assumed to be extended with None items. If /function/
   is None, the identity function is assumed; if there are multiple
   arguments, map() #map returns a list consisting of tuples
   containing the corresponding items from all iterables (a kind of
   transpose operation). The /iterable/ arguments may be a sequence or
   any iterable object; the result is always a list.

 print map(lambda x, y : x + y,  (1,2,3), (4,5,6))
[5, 7, 9]



--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-Help] What is lambdas in Python??

2011-12-27 Thread R. Alan Monroe
 I really don't get it. What is lambda? I keep seeing   it and I
 couldn't understand anything online about it.

It took me a while to get it too. It's for those rare times when you
want a throwaway function. Like you want to do something kind of
functioney without going to the trouble of writing a whole def
statement for it. Personally, I usually use it when I need to do custom
sorts.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python help on unicode needed....

2011-03-11 Thread cocron
Hello Danny,



Can you perhaps help me on a python Unicode issue?



I have an audio collection of many chinese titles on my music

Database.

I would like to rename all music titles in the directories and
subdirectories to either their ascii values (preceeding with a certain
character/s like “xx-“ or just delete the chinese characters from the dir
name and file names.



Do you have a simple solution for the batch renaming issue?



Many thanks in advance



István




many thanks!

-- 
 the more you give, the more you have  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2010-09-28 Thread masawudu bature
Thanks David, But the loop was suppose to produce the count of even divisors an 
integer has.
Like, 6 has 2 even divisors, which is 2 and 6, itself.
8 = 3 even divisors, which is 2, 4 ,and 8
10 = 2 even divisors, which is 2, and 10
12 = 4 even divisors, which is 2, 4, 6, and 12

sorry, I just don't know how to write a code to count the number of divisors





From: David Hutto smokefl...@gmail.com
To: masawudu bature mass0...@yahoo.ca
Cc: tutor@python.org
Sent: Mon, September 27, 2010 11:36:05 PM
Subject: Re: [Tutor] Python Help

On Tue, Sep 28, 2010 at 12:15 AM, masawudu bature mass0...@yahoo.ca wrote:
 I'm having a hard time finding the count of divisors that are even. Help
 anybody?

 Here's my code.

 The output is suppose to count the number of even divisors the range has.

 def evenCount(b) :
 for n in range(x, y+1) :
 count = 0
 if n % 2 == 0 :
 count += n/3
 count % n == 1
 return n


 ### main 

 x = input(Enter a starting value: )
 y = input(Enter a stopping value: )

 count = evenCount(x)

 for n in range(x, y+1) :
 count = 0
 if n % 2 == 0 :
 count += n/3
 print %2d:  %n, has%2d %count, even divisors,
 else :
 print %2d:  %n, has 0 even divisors,
 print



 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor



#You start with your range variables
x = input(Enter a starting value: )
y = input(Enter a stopping value: )

#You set a for loop for range
for num in range(x, y):
#If that number divided by 2 has a remainder of 0, it's of course even.
if num % 2 == 0:
#print the number
print num

And various other ways as well.

David



  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2010-09-28 Thread Alan Gauld


masawudu bature mass0...@yahoo.ca wrote

The output is suppose to count the number of even divisors the range 
has.


You need to work this through again in your head:


def evenCount(b) :


This function takes a parameter b but you never use b in the 
function...



   for n in range(x, y+1) :


What are x and y supposed to be? They must be defined
outside the function? Don;t you really want your loop to check
the values for b? So it would be range(0,b+1)?


   count = 0


You reset count to zero for each time through the loop - do
you really want to do that?


   if n % 2 == 0 :
   count += n/3


Why do you add n/3?


   count % n == 1


This is a boolean expression that will evaluate to TRue or False
and which you then ignore. It does nothing useful.


   return n


And this will always return the first value of your loop, x.

Try working through it on paper, writing down the values of each 
variable
in the function  for each time through the loop. Are they what you 
expect?


HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


  1   2   >