[Tutor] (no subject)

2019-08-06 Thread Stephen Tenbrink


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


Re: [Tutor] (no subject)

2019-03-26 Thread Matthew Herzog
 elif fileDate = datetime.strptime(name[0:8], DATEFMT).date():
   ^
SyntaxError: invalid syntax



On Sat, Mar 23, 2019 at 6:43 PM Mats Wichmann  wrote:

> On 3/23/19 3:16 AM, Peter Otten wrote:
>
> > Personally I would use a try...except clause because with that you can
> > handle invalid dates like _etc.xls gracefully. So
> >
> > ERASED = "erased_"
> >
> >
> > def strip_prefix(name):
> > if name.startswith(ERASED):
> > name = name[len(ERASED):]
> > return name
> >
> >
> > def extract_date(name):
> > datestr = strip_prefix(name)[:8]
> > return datetime.datetime.strptime(datestr, DATEFMT).date()
> >
> >
> > for name in ...:
> > try:
> > file_date = extract_date(name)
> > except ValueError:
> > pass
> > else:
> > print(file_date)
>
> I'd endorse this approach as well.. with a DATEFMT of "%Y%m%d", you will
> get a ValueError for every date string that is not a valid date... which
> you then just ignore (the "pass"), since that's what you wanted to do.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
The plural of anecdote is not "data."
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2019-03-26 Thread Mats Wichmann
On 3/26/19 12:26 PM, Matthew Herzog wrote:
> elif fileDate = datetime.strptime(name[0:8], DATEFMT).date():
>                    ^
> SyntaxError: invalid syntax

are you assigning (=) or comparing (==)?

you can't do both in one statement because of the side effect implications.

[except that starting with Python 3.8 you will be able to (see PEP 572),
but that will be a brand new operator,  := ]


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


Re: [Tutor] (no subject)

2019-03-23 Thread Mats Wichmann
On 3/23/19 3:16 AM, Peter Otten wrote:

> Personally I would use a try...except clause because with that you can 
> handle invalid dates like _etc.xls gracefully. So
> 
> ERASED = "erased_"
> 
> 
> def strip_prefix(name):
> if name.startswith(ERASED):
> name = name[len(ERASED):]
> return name
> 
> 
> def extract_date(name):
> datestr = strip_prefix(name)[:8]
> return datetime.datetime.strptime(datestr, DATEFMT).date()
> 
> 
> for name in ...:
> try:
> file_date = extract_date(name)
> except ValueError:
> pass
> else:
> print(file_date)

I'd endorse this approach as well.. with a DATEFMT of "%Y%m%d", you will
get a ValueError for every date string that is not a valid date... which
you then just ignore (the "pass"), since that's what you wanted to do.

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


Re: [Tutor] (no subject)

2019-03-23 Thread Peter Otten
Matthew Herzog wrote:

> I have a Python3 script that reads the first eight characters of every
> filename in a directory in order to determine whether the file was created
> before or after 180 days ago based on each file's name. The file names all
> begin with MMDD or erased_MMDD_etc.xls. I can collect all these
> filenames already.
> I need to tell my script to ignore any filename that does not conform to
> the standard eight leading numerical characters, example: 20180922 or
> erased_20171207_1oIkZf.so.
> Here is my code.
> 
> if name.startswith('scrubbed_'):
> fileDate = datetime.strptime(name[9:17], DATEFMT).date()
> else:
> fileDate = datetime.strptime(name[0:8], DATEFMT).date()
> 
> I need logic to prevent the script from 'choking' on files that don't fit
> these patterns. The script needs to carry on with its work and forget
> about non-conformant filenames. Do I need to add code that causes an
> exception or just add an elif block?

Personally I would use a try...except clause because with that you can 
handle invalid dates like _etc.xls gracefully. So

ERASED = "erased_"


def strip_prefix(name):
if name.startswith(ERASED):
name = name[len(ERASED):]
return name


def extract_date(name):
datestr = strip_prefix(name)[:8]
return datetime.datetime.strptime(datestr, DATEFMT).date()


for name in ...:
try:
file_date = extract_date(name)
except ValueError:
pass
else:
print(file_date)


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


Re: [Tutor] (no subject)

2019-03-22 Thread Cameron Simpson

On 22Mar2019 17:45, Matthew Herzog  wrote:

I have a Python3 script that reads the first eight characters of every
filename in a directory in order to determine whether the file was created
before or after 180 days ago based on each file's name. The file names all
begin with MMDD or erased_MMDD_etc.xls. I can collect all these
filenames already.
I need to tell my script to ignore any filename that does not conform to
the standard eight leading numerical characters, example: 20180922 or
erased_20171207_1oIkZf.so.
Here is my code.

if name.startswith('scrubbed_'):
   fileDate = datetime.strptime(name[9:17], DATEFMT).date()
   else:
   fileDate = datetime.strptime(name[0:8], DATEFMT).date()

I need logic to prevent the script from 'choking' on files that don't fit
these patterns. The script needs to carry on with its work and forget about
non-conformant filenames. Do I need to add code that causes an exception or
just add an elif block?


Just an elif. Untested example:

 for name in all_the_filenames:
   if name.startswith('erased_') and has 8 digits after that:
   extract date after "erased" ...
   elif name starts with 8 digits:
   extract date at the start
   else:
 print("skipping", repr(name))
 continue
   ... other stuff using the extracted date ...

The "continue" causes execution to go straight to the next loop 
iteration, effectively skipping the rest of the loop body. An exception 
won't really do what you want (well, not neatly).


Alan's suggestion of a regexp may be a sensible way to test filenames 
for conformance to your rules. \d{8} matches 8 digits. It doesn't do any 
tighter validation such as sane year, month or day values:  
would be accepted. Which may be ok, and it should certainly be ok for 
your first attempt: tighten things up later.


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


Re: [Tutor] (no subject)

2019-03-22 Thread Alan Gauld via Tutor

On 22/03/19 21:45, Matthew Herzog wrote:


I need to tell my script to ignore any filename that does not conform to
the standard eight leading numerical characters, example: 20180922 or
erased_20171207_1oIkZf.so.


Normally we try to dissuade people from using regex when string methods 
will do but in this case a regex sounds like it might be the best option.


A single if statement should suffice

if re.match("[0-9]{8}|erased_",fname):
   Your code here

There are other ways to write the regex but the above should
be clear...

HTH,

Alan G.

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


[Tutor] (no subject)

2019-03-22 Thread Matthew Herzog
I have a Python3 script that reads the first eight characters of every
filename in a directory in order to determine whether the file was created
before or after 180 days ago based on each file's name. The file names all
begin with MMDD or erased_MMDD_etc.xls. I can collect all these
filenames already.
I need to tell my script to ignore any filename that does not conform to
the standard eight leading numerical characters, example: 20180922 or
erased_20171207_1oIkZf.so.
Here is my code.

if name.startswith('scrubbed_'):
fileDate = datetime.strptime(name[9:17], DATEFMT).date()
else:
fileDate = datetime.strptime(name[0:8], DATEFMT).date()

I need logic to prevent the script from 'choking' on files that don't fit
these patterns. The script needs to carry on with its work and forget about
non-conformant filenames. Do I need to add code that causes an exception or
just add an elif block?

Thanks.


-- 
The plural of anecdote is not "data."
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2019-03-18 Thread Tobiah

You need a space between 'def' and '__init__'.
Then you must remove the import statement.  The class
is already defined in your scope and there is no
module called 'Student'.


Tobiah

On 3/15/19 6:54 PM, Glenn Dickerson wrote:

class Student():

 def__init__(self, name, major, gpa, is_on_probation):
 self.name = name
 self.major = major
 self.gpa = gpa
 self.is_on_probation = is_on_probation


import Student
student1 = Student('Jim', 'Business', 3.1, False)
student2 = Student('Pam', 'Art', 2.5, True)
print(student1.name)
print(student2.gpa)



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


Re: [Tutor] (no subject)

2019-03-16 Thread Peter Otten
Glenn Dickerson wrote:

> class Student():
> 
> def__init__(self, name, major, gpa, is_on_probation):
> self.name = name
> self.major = major
> self.gpa = gpa
> self.is_on_probation = is_on_probation
> 
> 
> import Student
> student1 = Student('Jim', 'Business', 3.1, False)
> student2 = Student('Pam', 'Art', 2.5, True)
> print(student1.name)
> print(student2.gpa)
> 
> I entered this in IDLE and it failed. Any advice?

First of all, try to be as precise as you can with your error descriptions.
What was the exact error, what looked the traceback like?

Do not retype, use cut-and-paste to put them into your post.

Was it something like

  File "Student.py", line 3
def__init__(self, name, major, gpa, is_on_probation):
^
SyntaxError: invalid syntax

Then the problem is the missing space between the keyword "def" and the 
method name "__init__".

Or was it

Traceback (most recent call last):
  File "student.py", line 10, in 
import Student
ImportError: No module named 'Student'

That's because Student is a class rather than a module, and you neither
need to nor can import it directly. If you remove the import statement your 
code should work.

But wait, there's another option. If you saw

Traceback (most recent call last):
  File "Student.py", line 10, in 
import Student
  File "Student.py", line 11, in 
student1 = Student('Jim', 'Business', 3.1, False)
TypeError: 'module' object is not callable

then a "Student" module was imported successfully. However, as it has the 
same name as your class, the name "Student" is now bound to the module, and 
unlike the class a module cannot be called. The solution then is to rename 
the module, from Student.py to student.py, say, as lowercase module names 
are the preferred convention anyway.

So there are at least three possible problems in your tiny and almost 
correct code snippet. 

In a script that does some actual work the number of possible problems 
explodes, and that's why most of us don't even start to debug a piece of 
code without a detailed error description and a traceback -- it's usually a 
waste of time.


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


Re: [Tutor] (no subject)

2019-03-16 Thread Alan Gauld via Tutor
On 16/03/2019 01:54, Glenn Dickerson wrote:
> class Student():
> 
> def__init__(self, name, major, gpa, is_on_probation):
> self.name = name
> self.major = major
> self.gpa = gpa
> self.is_on_probation = is_on_probation
> 
> 
> import Student
> student1 = Student('Jim', 'Business', 3.1, False)
> student2 = Student('Pam', 'Art', 2.5, True)
> print(student1.name)
> print(student2.gpa)
> 
> I entered this in IDLE and it failed. Any advice? Thank you.

Please, never just say "it failed".
How did it fail?
Did you get an error message? If so, send us the complete message
Did IDLE crash?
Did the PC crash?
Did it run with no output?
Did it run with the wrong output?

There are so many ways for a program to "fail" we need
more specific details.

In this case I can guess what might have happened.
I suspect you need to read up on how to import and
use an external file, but again there are at least
3 possible errors that you might have and I can't
tell which from the details you provided.


-- 
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] (no subject)

2019-03-16 Thread Steven D'Aprano
Hi Glenn, and welcome.

On Fri, Mar 15, 2019 at 09:54:41PM -0400, Glenn Dickerson wrote:
> class Student():
> def__init__(self, name, major, gpa, is_on_probation):
> self.name = name
> self.major = major
> self.gpa = gpa
> self.is_on_probation = is_on_probation
> 
> 
> import Student
> student1 = Student('Jim', 'Business', 3.1, False)
> student2 = Student('Pam', 'Art', 2.5, True)
> print(student1.name)
> print(student2.gpa)
> 
> I entered this in IDLE and it failed. Any advice? Thank you.

Yes -- read the error message. What does it say?


(Reading, and understanding, error messages is probably the most 
important skill a programmer can have.)



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


[Tutor] (no subject)

2019-03-16 Thread Glenn Dickerson
class Student():

def__init__(self, name, major, gpa, is_on_probation):
self.name = name
self.major = major
self.gpa = gpa
self.is_on_probation = is_on_probation


import Student
student1 = Student('Jim', 'Business', 3.1, False)
student2 = Student('Pam', 'Art', 2.5, True)
print(student1.name)
print(student2.gpa)

I entered this in IDLE and it failed. Any advice? Thank you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2018-11-14 Thread Whitney Eichelberger via Tutor
I need help creating a weighted GPA calculator. I attempted to create one but I 
was unable to incorporate different leveled classes (College Prep, Honors, and 
AP). How can I incorporate those leveled classes into the calculator in order 
to get a final GPA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2018-11-12 Thread Avi Gross
In replying to what "Stealth Fleet" asked, I have too many comments,
starting with a suggestion to put a SUBECT on the Subject: line.

Your first error was not converting the text input to an integer or floating
point number.

tokenAmount = input( "How many tokens would you like to buy or cash
in?:  ")

Fix that and then see if other things fail.

BTW, you created functions which take no arguments and use a global variable
but then create local variables that would not persist in a real
application. If your assignment was just to print what would have been
calculated, that may suffice but that may be another area you think more
about.


-Original Message-
From: Tutor  On Behalf Of
Stealth Fleet
Sent: Sunday, November 11, 2018 6:00 PM
To: tutor@python.org
Subject: [Tutor] (no subject)

tokenAmount = input( "How many tokens would you like to buy or cash in?:  ")

print (tokenAmount)



def buy ():

if tokenAmount <= 400:

buy = tokenAmount * .2099

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount > "400" <= "549":

buy = tokenAmount * .3999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount >= "550" <= "749":

buy = tokenAmount * .4999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount >= "750" <= "999":

buy = tokenAmount * .6299

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

else:

buy = tokenAmount * .7999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")



def cashIn ():

cashIn = tokenAmount * .05

print( "The amount of money you will receive is $"+ (cashIn))



tokenAmount works but the buy and cashIn are not being ran why? When I put
"print(buy, cashIn)" it gives me a long message that ends in an error any
and all help is greatly appreciated. Sent from Mail
<https://go.microsoft.com/fwlink/?LinkId=550986> 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] (no subject)

2018-11-11 Thread Steven D'Aprano
On Sun, Nov 11, 2018 at 03:00:00PM -0800, Stealth Fleet wrote:

[...]
> tokenAmount works but the buy and cashIn are not being ran why?

You define the function, but never call it. Functions aren't called 
automatically.

py> def example():
... print("calling example")
...
py>
py> # nothing is happening yet...
...
py> example()  # call the function
calling example


> When I put
> "print(buy, cashIn)" it gives me a long message that ends in an error

Would you like to tell us that message, or would you prefer that we make 
a wild guess?

Please COPY AND PASTE (don't summarise or retype from memory) the ENTIRE 
error message, not just the last line, and especially DON'T take a 
screen shot or photo and send that.



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


[Tutor] (no subject)

2018-11-11 Thread Stealth Fleet
tokenAmount = input( "How many tokens would you like to buy or cash in?:  ")

print (tokenAmount)



def buy ():

if tokenAmount <= 400:

buy = tokenAmount * .2099

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount > "400" <= "549":

buy = tokenAmount * .3999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount >= "550" <= "749":

buy = tokenAmount * .4999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount >= "750" <= "999":

buy = tokenAmount * .6299

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

else:

buy = tokenAmount * .7999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")



def cashIn ():

cashIn = tokenAmount * .05

print( "The amount of money you will receive is $"+ (cashIn))



tokenAmount works but the buy and cashIn are not being ran why? When I put
"print(buy, cashIn)" it gives me a long message that ends in an error any
and all help is greatly appreciated. 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] (no subject)

2018-10-27 Thread Bob Gailer
On Oct 27, 2018 7:48 AM, "Jesse Stockman"  wrote:
>
> Hi there
>
> I need to draw a patten with turtle in python 3.7 but I cant get it to
work here are the specs of the pattern and my code so far can you please
help

Thank you for asking for help. It would help us if you were more specific.
"Can't get it to work" doesn't tell us much.

Does the program run or do you get an error?

If you get an error, also known as a traceback, copy the entire traceback
and paste it into your reply.

Otherwise show us your input and output. Tell us where it differs from what
you expected. Again use copy and paste to show your results.
>
> • Specifications of the pattern o The radius of the three heads is 10.
> o The length of legs is 30. o The length of the sizes of the two
triangles (the body of runner-up and third-place) is 40. They are all
equal-size triangles. The winner’s body is a 40x40 square. o The width of
the three blocks of the podium is 60. The heights are 90, 60, and 40
respectively.
>
> And my code so far
>
> from turtle import *
>
> x = 0
> y = 0
> radius = 0
> x1 = 0
> x2 = 0
> y1 = 0
> y2 = 0
> color = 0
> width = 0
> hight =0
>
>
>
> def main():
> speed(0)
> pensize(3)
> pencolor("black")
>
> winner_color = "red"
> second_color = "orange"
> third_color = "purple"
> draw_podium(winner_color, second_color, third_color)
> darw_third(third_color)
> draw_winner(winner_color)
> draw_second(second_color)
>
> def move_to(x, y):
> x = int(input("input X coordinate: "))
> y = int(input("input y coordinate: "))
> penup()
> goto(x, y)
> pendown()
>
> def draw_head(x, y, radius):
> radius = int(input("input radius: "))
> move_to(x, y)
> circle(radius)
>
> def draw_line(x1, y1, x2, y2):
> x1 = int(input("line start X: "))
> y1 = int(input("line start Y: "))
> x2 = int(input("line end X: "))
> y2 = int(input("line end Y: "))
> penup()
> goto(x1,y1)
> pendown()
> goto(x2,y2)
>
> def draw_block(x, y, hight, width, color):
> move_to(x, y)
> hight = int(input("input hight: "))
> width = int(input("input width: "))
> color(winner_color)
> begin_fill()
> forward(width)
> left(90)
> forward(hight)
> left(90)
> forward(width)
> left(90)
> forward(hight)
> end_fill()
>
>
> main()
> draw_block(x, y, hight, width, color)
>
>
> exitonclick()
>
>
> please help me
> thank you
> kind regards
> Tarantulam
>
>
> 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] (no subject)

2018-10-27 Thread boB Stepp
Greetings!

On Sat, Oct 27, 2018 at 6:48 AM Jesse Stockman
 wrote:
>
> Hi there
>
> I need to draw a patten with turtle in python 3.7 but I cant get it to work 
> ...

What is the problem?  Describe what you expected to happen, what did
happen, and *copy and paste* the Traceback that Python generates.  I
had a bit of time, so I ran your code as you had it in your email, and
I got the following:

Traceback (most recent call last):
  File "draw_body.py", line 69, in 
main()
  File "draw_body.py", line 26, in main
draw_podium(winner_color, second_color, third_color)
NameError: name 'draw_podium' is not defined

If you look at your code, your main() function calls this
draw_podium() function, but you never give us that function in your
email.  Likewise, darw_third() [Note the spelling error here.],
draw_winner(), and draw_second() are not defined anywhere in the code
you provided.  Looks like your next step is to write those functions.
BTW "hight" should be "height", but as long as you are consistent,
that spelling error should not cause any issues.

One thing you can do to check for further issues with the code you
*have* written so far, is to provide the missing functions with "pass"
in each function's body, and then run your program and see if any
other errors emerge.  E.g.,

draw_podium(winner_color, second_color, third_color):
pass

draw_third(third_color):
pass

Etc.

Hope this helps!

> ...here are the specs of the pattern and my code so far can you please help
>
> • Specifications of the pattern o The radius of the three heads is 10.
> o The length of legs is 30. o The length of the sizes of the two triangles 
> (the body of runner-up and third-place) is 40. They are all equal-size 
> triangles. The winner’s body is a 40x40 square. o The width of the three 
> blocks of the podium is 60. The heights are 90, 60, and 40 respectively.
>
> And my code so far
>
> from turtle import *
>
> x = 0
> y = 0
> radius = 0
> x1 = 0
> x2 = 0
> y1 = 0
> y2 = 0
> color = 0
> width = 0
> hight =0
>
>
>
> def main():
> speed(0)
> pensize(3)
> pencolor("black")
>
> winner_color = "red"
> second_color = "orange"
> third_color = "purple"
> draw_podium(winner_color, second_color, third_color)
> darw_third(third_color)
> draw_winner(winner_color)
> draw_second(second_color)
>
> def move_to(x, y):
> x = int(input("input X coordinate: "))
> y = int(input("input y coordinate: "))
> penup()
> goto(x, y)
> pendown()
>
> def draw_head(x, y, radius):
> radius = int(input("input radius: "))
> move_to(x, y)
> circle(radius)
>
> def draw_line(x1, y1, x2, y2):
> x1 = int(input("line start X: "))
> y1 = int(input("line start Y: "))
> x2 = int(input("line end X: "))
> y2 = int(input("line end Y: "))
> penup()
> goto(x1,y1)
> pendown()
> goto(x2,y2)
>
> def draw_block(x, y, hight, width, color):
> move_to(x, y)
> hight = int(input("input hight: "))
> width = int(input("input width: "))
> color(winner_color)
> begin_fill()
> forward(width)
> left(90)
> forward(hight)
> left(90)
> forward(width)
> left(90)
> forward(hight)
> end_fill()
>
>
> main()
> draw_block(x, y, hight, width, color)
>
>
> exitonclick()




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


[Tutor] (no subject)

2018-10-27 Thread Asad
Hi All ,

  I found a logic :

1.initialize print flag to false
2. Save starting and ending times in variables
3. loop to read or process sequential lines in the file
  a. See if line contains time
  b. If it does, extract time
  c. Compare time in line to starting time
  d. If line time is greater than or equal to start time, set print flag to
true
  e. If line time is greater than ending time, set print flag to false
  f. If print flag is true print line
  g. End of loop — process next line

start_time = 2018-10-22 10:21:15
end_time = 2018-10-22 10:21:25

f4 = open ( r"logC11.txt", 'r' )

for line in f4.readlines():
  a = re.findall( r'\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]', line )
  print a
  #b = a.group(0)
  newtime = datetime.datetime.strptime ( a[0], '%m/%d/%y %H:%M:%S' )
  print newtime
  if newtime > y and newtime < k:
flag = True
  else:
flag = False
  if flag :
print line
  else :
continue


But it errors out :

C:\Python27\python.exe D:/QI/test_qopatch.py
Traceback (most recent call last):
2018-10-22 10:21:15
  File "D:/QI/test_qopatch.py", line 32, in 
2018-10-22 10:21:25
newtime = datetime.datetime.strptime ( a[0], '%m/%d/%y %H:%M:%S' )
['04/26/18 06:11:52']
2018-04-26 06:11:52
[]
IndexError: list index out of range

Process finished with exit code 1


Please provide the code

Thanks,

On Sat, Oct 27, 2018 at 1:35 PM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. Re: How to print lines within two timestamp (Alan Gauld)
>2. Re: Python Help (Alan Gauld)
>3. Re: How to print lines within two timestamp (Peter Otten)
>4. How to print lines within two timestamp (Asad)
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Fri, 26 Oct 2018 23:30:09 +0100
> Subject: Re: [Tutor] How to print lines within two timestamp
> On 26/10/2018 18:45, Alan Gauld via Tutor wrote:
>
> > It woiyukld
>
> No idea what happened there. Should be "would" of course!
>
> --
> 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
>
>
>
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Fri, 26 Oct 2018 23:34:17 +0100
> Subject: Re: [Tutor] Python Help
> 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
>
>
>
>
>
>
> -- Forwarded message --
> From: Peter Otten <__pete...@web.de>
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sat, 27 Oct 2018 06:07:43 +0200
> Subject: Re: [Tutor] How to print lines within two timestamp
> Alan Gauld via Tutor wrote:
>
> > On 26/10/2018 18:45, Alan Gauld via Tutor wrote:
> >
> >> It woiyukld
> >
> > No idea what happened there. Should be "would" of course!
>
> Of coiyukrse! Nobody thoiyukght otherwiiyske :)
>
>
>
>
>
> -- Forwarded message --
> From: Asad 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sat, 27 Oct 2018 12:32:51 +0530
> Subject: [Tutor] How to print lines within two timestamp
> On Sat, Oct 27, 2018 at 4:01 AM  wrote:
>
> > Send Tutor mailing list submissions to
> > tutor@python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> > https://mail.python.org/mailman/listinfo/tutor
> > or, via email, send a message with subject or body 'help' to
> > tutor-requ...@python.org
> >
> > You can reach the person managing the list at
> > tutor-ow...@python.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Tutor digest..."
> > Today's Topics:
> >
> >1. How to print lines within two timestamp (Asad)
> >2. Re: How to print lines within two timestamp (Alan Gauld)
> >3. Re: Python Help (Bob Gailer)
> >4. Re: Python Help (Adam Eyring)
> >5. Re: Python Help (Adam Eyring)
> >
> >
> >
> > -- Forwarded message --
> > From: Asad 
> > To: tutor@python.org
> > Cc:
> > 

[Tutor] (no subject)

2018-10-27 Thread Jesse Stockman
Hi there 

I need to draw a patten with turtle in python 3.7 but I cant get it to work 
here are the specs of the pattern and my code so far can you please help

• Specifications of the pattern o The radius of the three heads is 10. 
o The length of legs is 30. o The length of the sizes of the two triangles (the 
body of runner-up and third-place) is 40. They are all equal-size triangles. 
The winner’s body is a 40x40 square. o The width of the three blocks of the 
podium is 60. The heights are 90, 60, and 40 respectively. 

And my code so far

from turtle import *

x = 0
y = 0
radius = 0
x1 = 0
x2 = 0
y1 = 0
y2 = 0
color = 0
width = 0
hight =0



def main():
speed(0)
pensize(3)
pencolor("black")

winner_color = "red"
second_color = "orange"
third_color = "purple"
draw_podium(winner_color, second_color, third_color)
darw_third(third_color)
draw_winner(winner_color)
draw_second(second_color)

def move_to(x, y):
x = int(input("input X coordinate: "))
y = int(input("input y coordinate: "))
penup()
goto(x, y)
pendown()

def draw_head(x, y, radius):
radius = int(input("input radius: "))
move_to(x, y)
circle(radius)

def draw_line(x1, y1, x2, y2):
x1 = int(input("line start X: "))
y1 = int(input("line start Y: "))
x2 = int(input("line end X: "))
y2 = int(input("line end Y: "))
penup()
goto(x1,y1)
pendown()
goto(x2,y2)

def draw_block(x, y, hight, width, color):
move_to(x, y)
hight = int(input("input hight: "))
width = int(input("input width: "))
color(winner_color)
begin_fill()
forward(width)
left(90)
forward(hight)
left(90)
forward(width)
left(90)
forward(hight)
end_fill()

 
main()
draw_block(x, y, hight, width, color)


exitonclick()
 

please help me
thank you
kind regards
Tarantulam


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] (no subject)

2018-10-19 Thread Albert-Jan Roskam



On 19 Oct 2018 18:09, Pat Martin  wrote:

TLDR; How do you figure out if code is inefficient (if it isn't necessarily
obvious) and how do you find a more efficient

-
Hi, check this: https://docs.python.org/3/library/profile.html. Also, the 
timeit module is handy for smaller snippets.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2018-10-19 Thread Pat Martin
TLDR; How do you figure out if code is inefficient (if it isn't necessarily
obvious) and how do you find a more efficient solution?

I use code wars sometimes to get some practice with Python, there was a
challenge to compare two strings and if string1 had enough characters to be
rearranged to make string2 return True, otherwise return False.

I wrote a script that was like this:

for i in string1:
if i not in string2:
return False
string2.replace(i,"",1)
return True

This worked but I kept getting that my function was too inefficient and it
took too long. I did a search for the problem and found someone was using
collections.Counter. This basically takes the string and returns the number
of times each character occurs in it. Then just compare the count of one
string to another to see if there is enough of each letter to make the
other string. This seems like an elegant way to do it.

My question is, how do I know something is inefficient and more importantly
how do I go about finding a more efficient solution?

I have just discovered dir() and it has really helped in finding methods
for items but that doesn't help when finding actual packages especially if
I don't know exactly what I am looking for.

Sorry about the long email, not sure if there is even an answer to this
question except maybe write more code and get more experience?

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


Re: [Tutor] (no subject)

2018-06-01 Thread Alan Gauld via Tutor
On 31/05/18 07:06, erich callahana wrote:
> I’m not sure how to access this window 
>

Unfortunately this is a text mailing list and the server strips binary
attachments for security reasons. Either send us a link to a web
page or describe what it is you are trying to do.

Include the program name, the OS, and the Python version you
are using.

-- 
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] (no subject)

2018-06-01 Thread erich callahana
I’m not sure how to access this window 



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


Re: [Tutor] (no subject)

2018-04-25 Thread Kai Bojens
On 25/04/2018 –– 12:19:28PM -0600, Mats Wichmann wrote:
> I presume that's pseudo-code, since it's missing punctuation (commas
> between elements) and the country codes are not quoted

Yes, that was just a short pseudo code example of what I wanted to achieve. 
 
> you don't actually need to check (there's a Python aphorism that goes
> something like "It's better to ask forgiveness than permission").
 
> You can do:
 
> try:
> result[login_auth]['Countries'].append(login_country)
> except KeyError:
> # means there was no entry for login_auth
> # so add one here

I see. That'd be better indeed. The try/except concept is still rather new to me
and I still have to get used to it. 

Thanks for your hints! I'm sure that I can work with these suggestions ;)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2018-04-25 Thread Mats Wichmann
On 12/31/1969 05:00 PM,  wrote:
> Hello everybody,
> I'm coming from a Perl background and try to parse some Exim Logfiles into a
> data structure of dictionaries. The regex and geoip part works fine and I'd
> like to save the email adress, the countries (from logins) and the count of
> logins.
> 
> The structure I'd like to have:
> 
> result = {
> 'f...@bar.de': {
> 'Countries': [DE,DK,UK]
> 'IP': ['192.168.1.1','172.10.10.10']
> 'Count': [12]
> }
> 'b...@foo.de': {
> 'Countries': [DE,SE,US]
> 'IP': ['192.168.1.2','172.10.10.11']
> 'Count': [23]
> }
> }

I presume that's pseudo-code, since it's missing punctuation (commas
between elements) and the country codes are not quoted

> 
> I don't have a problem when I do these three seperately like this with a one
> dimensonial dict (snippet):
> 
> result = defaultdict(list)
> 
> with open('/var/log/exim4/mainlog',encoding="latin-1") as logfile:
> for line in logfile:
> result = pattern.search(line)
> if (result):
> login_ip = result.group("login_ip")
> login_auth =  result.group("login_auth")
> response = reader.city(login_ip)
> login_country = response.country.iso_code
> if login_auth in result and login_country in result[login_auth]:
> continue
> else:
> result[login_auth].append(login_country)
> else:
> continue
> 
> This checks if the login_country exists within the list of the specific
> login_auth key, adds them if they don't exist and gives me the results I want.
> This also works for the ip addresses and the number of logins without any 
> problems. >
> As I don't want to repeat these loops three times with three different data
> structures I'd like to do this in one step. There are two main problems I
> don't understand right now:
> 
> 1. How do I check if a value exists within a list which is the value of a key 
> which is again a value of a key in my understanding exists? What I like to do:
> 
>  if login_auth in result and (login_country in result[login_auth][Countries])
>   continue

you don't actually need to check (there's a Python aphorism that goes
something like "It's better to ask forgiveness than permission").

You can do:

try:
result[login_auth]['Countries'].append(login_country)
except KeyError:
# means there was no entry for login_auth
# so add one here

that will happily add another instance of a country if it's already
there, but there's no problem with going and cleaning the 'Countries'
value later (one trick is to take that list, convert it to a set, then
(if you want) convert it back to a list if you need unique values.

you're overloading the name result here so this won't work literally -
you default it outside the loop, then also set it to the regex answer...
I assume you can figure out how to fix that up.

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


Re: [Tutor] (no subject)

2018-03-28 Thread Mats Wichmann
On 03/28/2018 04:32 AM, Steven D'Aprano wrote:
> On Wed, Mar 28, 2018 at 03:08:00PM +0900, naoki_morih...@softbank.ne.jp wrote:
>> I want to install 3rd party module, ex openpyxl.
>> And I executed the following command in windows command prompt as follows:
>> pip install openpyxl
>> But pip is not recognized as executable command at windows.
> 
> What version of Python are you using?
> 
> If you have Python 3.4 or better, or Python 2.7.9, you can say:
> 
>   python -m ensurepip
> 
> at the Windows command prompt to install pip. If there are no 
> installation errors, then you can run 
> 
>   pip install openpyxl
> 
> at the Windows command prompt. No internet is needed for the first 
> command, but for the second you will need internet access.
> 
> https://docs.python.org/3/library/ensurepip.html
> 
> On Windows, if you have trouble running the "python" command, it might 
> be easier to use "py" instead:
> 
> https://docs.python.org/3/using/windows.html#from-the-command-line
> 
> 

I would add... modern Python on Windows includes pip, but pip is not in
the same directory as Python. So if you told the installer to add Python
to the path you could have something like (this is an example):

C:\Users\Foo\AppData\Local\Programs\Python\Python36-32

in your PATH, but pip is in the path

C:\Users\Foo\AppData\Local\Programs\Python\Python36-32\Tools

you can add the latter to your PATH as well; or, use

  python -m pip dosomething

in place of

  pip dosomething

That is, even if Windows doesn't have pip in its path, Python shguld
know how to find it as a module.



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


Re: [Tutor] (no subject)

2018-03-28 Thread shubham goyal
Use this link to install python package and make sure to add the path in
environment variables (just click the option it asks when you run the
setup, Add Python to path or something).
Recent python packages include pip also so you will get your problem solved.

https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe

In your case pip module is not installed or not added to windows
environment variables thats why its showing pip not recognized as a command.
do as mentioned and you should able to install whatever.

On Wed, Mar 28, 2018 at 11:38 AM,  wrote:

> I want to install 3rd party module, ex openpyxl.
> And I executed the following command in windows command prompt as follows:
> pip install openpyxl
> But pip is not recognized as executable command at windows.
> I also tried the same way in python command line.
> But the result is the same.
> SyntaxError: invalid syntax
>
> What should I do to use openpyxl ?
> ___
> 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] (no subject)

2018-03-28 Thread Steven D'Aprano
On Wed, Mar 28, 2018 at 03:08:00PM +0900, naoki_morih...@softbank.ne.jp wrote:
> I want to install 3rd party module, ex openpyxl.
> And I executed the following command in windows command prompt as follows:
> pip install openpyxl
> But pip is not recognized as executable command at windows.

What version of Python are you using?

If you have Python 3.4 or better, or Python 2.7.9, you can say:

  python -m ensurepip

at the Windows command prompt to install pip. If there are no 
installation errors, then you can run 

  pip install openpyxl

at the Windows command prompt. No internet is needed for the first 
command, but for the second you will need internet access.

https://docs.python.org/3/library/ensurepip.html

On Windows, if you have trouble running the "python" command, it might 
be easier to use "py" instead:

https://docs.python.org/3/using/windows.html#from-the-command-line


-- 
Steve

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


[Tutor] (no subject)

2018-03-28 Thread naoki_morihira
I want to install 3rd party module, ex openpyxl.
And I executed the following command in windows command prompt as follows:
pip install openpyxl
But pip is not recognized as executable command at windows.
I also tried the same way in python command line.
But the result is the same.
SyntaxError: invalid syntax

What should I do to use openpyxl ?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2018-02-14 Thread Mats Wichmann
On 02/14/2018 05:42 PM, Alan Gauld via Tutor wrote:
> On 14/02/18 19:18, Nathantheweird1 wrote:
>> I'm having a problem with my code on an interactive story. All the choices
>> work until the end. When the code reaches the end, it will print different
>> functions that aren't even set to be called in the code. I'm not sure what
>> I've done wrong and can't ask anyone for help because they're learning the
>> same rate as I am in my computer science class.
> 
> That shouldn't stop you.
> Everyone picks up different things, there's a pretty good chance
> that collectively you can solve the problem.

second that viewpoint...  I know the classroom environment is different,
but in most professional programming environments you will be working
collaboratively with a team and unless you've been told not to do so in
class, if it's not an exam, working with peers is a great way to learn
skills you will use forever. In the Open Source Software world there's a
famous quote "many eyeballs make all bugs shallow" (Eric Raymond, "The
Cathedral and the Bazaar", a free essay that will be worth a read
someday. It's often referred to as Linus' Law).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2018-02-14 Thread Alan Gauld via Tutor
On 14/02/18 19:18, Nathantheweird1 wrote:
> I'm having a problem with my code on an interactive story. All the choices
> work until the end. When the code reaches the end, it will print different
> functions that aren't even set to be called in the code. I'm not sure what
> I've done wrong and can't ask anyone for help because they're learning the
> same rate as I am in my computer science class.

That shouldn't stop you.
Everyone picks up different things, there's a pretty good chance
that collectively you can solve the problem.

>  If you would like, I can
> send you a link to my code on pythonroom.com.

Well yes. We aren't psychic so, without seeing the code, we haven't
a hope of guessing what you have done.

-- 
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] (no subject)

2018-02-14 Thread Nathantheweird1
I'm having a problem with my code on an interactive story. All the choices
work until the end. When the code reaches the end, it will print different
functions that aren't even set to be called in the code. I'm not sure what
I've done wrong and can't ask anyone for help because they're learning the
same rate as I am in my computer science class. If you would like, I can
send you a link to my code on pythonroom.com.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-11-12 Thread Steven D'Aprano
Sorry 劉權陞 <01patrick...@gmail.com>, but this is an English-language 
mailing list. I do not understand what question you are asking.


On Sun, Nov 12, 2017 at 11:54:52PM +0800, 劉權陞 wrote:
> 我在使用closure 時,遇到了一些問題。
> 例如一個簡單的例子,
> 
> def f1(a):
> def f2(b):
> return a+b
> return f2
> 
> f1=f1(10)
> 
> 這時f1會發生衝突 ,這是正常的嗎?


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


Re: [Tutor] (no subject)

2017-11-12 Thread Alan Gauld via Tutor
On 12/11/17 15:54, 劉權陞 wrote:
> 我在使用closure 時,遇到了一些問題。
> 例如一個簡單的例子,
> 
> def f1(a):
> def f2(b):
> return a+b
> return f2
> 
> f1=f1(10)
> 
> 這時f1會發生衝突 ,這是正常的嗎?

Can you tell us what language this is?
Or better still post an English translation?
That's what most of us speak on this list...


-- 
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] (no subject)

2017-11-12 Thread 劉權陞
我在使用closure 時,遇到了一些問題。
例如一個簡單的例子,

def f1(a):
def f2(b):
return a+b
return f2

f1=f1(10)

這時f1會發生衝突 ,這是正常的嗎?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-10-05 Thread Mats Wichmann
On 10/03/2017 06:29 PM, Alan Gauld via Tutor wrote:
> On 03/10/17 22:49, steve.lett...@gmail.com wrote:
> 
>> That is guessesTaken. It reads 0 when it should be a larger number.
> 
> What makes you think so?
> You never increase it from its initial value so, quite correctly it
> stays at zero.

Adding some optimization thoughts below in addition:

> 
>> I am a beginner having another try to get it!
> 
> Remember the computer just does what you tell it and nothing more.
> It has no idea what you are trying to do so it needs you to tell it
> exactly what to do. Every single thing.
> 
> And in this case you need to add 1 to guessesTaken each time
> the user makes a guess.
> 
>> # This is a Guess the Number game.
>> import random
>>
>> guessesTaken = 0
>>
>> print('Hello! What is your name?')
>> myName = input()
>>
>> number = random.randint(1, 20)
>> print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
>>
>> for i in range(6):
>>     print('Take a guess.') # Four spaces in front of "print"
>>     guess = input()
>>     guess = int(guess)
> 
> you probably should have a line here like:
> 
>   guesesTaken += 1
> 
>>     if guess < number:
>>     print('Your guess is too low.') # Eight spaces in front of "print"
>>
>>     if guess > number:
>>     print('Your guess is too high.')
>>
>>     if guess == number:
>>     break

This sequence doesn't feel ideal: if guess == number you break out of
the script, then the first thing thereafter is you do the same check
again.  Why not move that work up to the first check inside the for loop?

>> if guess == number:
>>     guessesTaken = str(guessesTaken)
>>     print('Good job, ' + myName + '! You guessed my number in ' +
>>   guessesTaken + ' guesses!')
>>
>> if guess != number:
>>     number = str(number)
>>    print('Nope. The number I was thinking of was ' + number + '.')

Second, you need to still detect the case where you exited the loop
without ever matching.  But it doesn't have to be a disconnected test
like this one which risks at some time becoming detached - maybe you add
some code in front of it, then later change it, then change it some more
and at some point guess becomes changed and the test is invalid.  It
sounds silly here, but this happens in real code that is more complex.

Python has a syntax feature to help you out here: the for statement can
take an else clause, which means "finished the loop without otherwise
breaking out of it".  This would make the conceptual flow look like:

for i in maximum-guesses:
# prompt for guess
# guidance if wrong
if correct:
# congratulate
break
else:
# guesses ran out, commiserate



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


Re: [Tutor] (no subject)

2017-10-03 Thread Alan Gauld via Tutor
On 03/10/17 22:49, steve.lett...@gmail.com wrote:

> That is guessesTaken. It reads 0 when it should be a larger number.

What makes you think so?
You never increase it from its initial value so, quite correctly it
stays at zero.

> I am a beginner having another try to get it!

Remember the computer just does what you tell it and nothing more.
It has no idea what you are trying to do so it needs you to tell it
exactly what to do. Every single thing.

And in this case you need to add 1 to guessesTaken each time
the user makes a guess.

> # This is a Guess the Number game.
> import random
> 
> guessesTaken = 0
> 
> print('Hello! What is your name?')
> myName = input()
> 
> number = random.randint(1, 20)
> print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
> 
> for i in range(6):
>     print('Take a guess.') # Four spaces in front of "print"
>     guess = input()
>     guess = int(guess)

you probably should have a line here like:

  guesesTaken += 1

>     if guess < number:
>     print('Your guess is too low.') # Eight spaces in front of "print"
> 
>     if guess > number:
>     print('Your guess is too high.')
> 
>     if guess == number:
>     break
> 
> if guess == number:
>     guessesTaken = str(guessesTaken)
>     print('Good job, ' + myName + '! You guessed my number in ' +
>   guessesTaken + ' guesses!')
> 
> if guess != number:
>     number = str(number)
>    print('Nope. The number I was thinking of was ' + number + '.')
-- 
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] (no subject)

2017-10-03 Thread steve.lett777
Can u please tell me why this program does not work in line 28? That is 
guessesTaken. It reads 0 when it should be a larger number.

I am a beginner having another try to get it!

Thank you, Steve

PS. Python 3.5.1 and Win10

# This is a Guess the Number game.
import random

guessesTaken = 0

print('Hello! What is your name?')
myName = input()

number = random.randint(1, 20)
print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')

for i in range(6):
    print('Take a guess.') # Four spaces in front of "print"
    guess = input()
    guess = int(guess)

    if guess < number:
    print('Your guess is too low.') # Eight spaces in front of "print"

    if guess > number:
    print('Your guess is too high.')

    if guess == number:
    break

if guess == number:
    guessesTaken = str(guessesTaken)
    print('Good job, ' + myName + '! You guessed my number in ' +
  guessesTaken + ' guesses!')

if guess != number:
    number = str(number)
   print('Nope. The number I was thinking of was ' + number + '.')


Sent from Mail for Windows 10

From: tutor-requ...@python.org
Sent: Tuesday, 3 October 2017 3:02 AM
To: tutor@python.org
Subject: Tutor Digest, Vol 164, Issue 5





---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-09-19 Thread Alan Gauld via Tutor
On 19/09/17 15:11, C wrote:
> Hi Python tutor, I require help for a script that asks user for number of
> rows, r and number of columns c, and generates a r x c matrix with the
> following values:

You already posted this in another thread, please do not multi-post it
just clutters up the archive and splits the discussion. you already have
replies on the original post.

-- 
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] (no subject)

2017-09-19 Thread C
Hi Python tutor, I require help for a script that asks user for number of
rows, r and number of columns c, and generates a r x c matrix with the
following values:

- The value of each element in the first row is the number of the column
- The value of each element in the first column is the number of the row
- The rest of the elements each has a value equal to the sum of the element
above it and the element to the left.

Example of such matrix if a user inputs r=4 and c=5

12 3 4 5
24 711   16
3714   25   41
4   1125   50   91

For now I only filled up the first row and first columns.

We were told to use the for loops as well as numpy for this. However, I
cannot quite figure out how I can use loops to do this. Please help!

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


Re: [Tutor] (no subject)

2017-08-17 Thread Mats Wichmann
On 08/17/2017 05:45 AM, Howard Lawrence wrote:
> Yes, it does.
> 
> On Aug 16, 2017 8:02 PM, "Zachary Ware" 
> wrote:
> 
> Hi Howard,
> 
> On Wed, Aug 16, 2017 at 5:36 PM, Howard Lawrence <1019sh...@gmail.com>
> wrote:
>> class Address:
>> def _init_(self,Hs,St,Town,Zip):
> 
> Your issue is in this line, it should be `__init__` rather than
> `_init_` (that is, two underscores before and after "init").
> 
> Hope this helps,


I would add that typography in a web browser, and sometimes even on the
printed page, may not make the double underscores ('dunder') actually
clearly look like two characters, so until one runs into this lesson The
Hard Way, it might be an easy mistake to make.


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


Re: [Tutor] (no subject)

2017-08-17 Thread Howard Lawrence
Yes, it does.

On Aug 16, 2017 8:02 PM, "Zachary Ware" 
wrote:

Hi Howard,

On Wed, Aug 16, 2017 at 5:36 PM, Howard Lawrence <1019sh...@gmail.com>
wrote:
> class Address:
> def _init_(self,Hs,St,Town,Zip):

Your issue is in this line, it should be `__init__` rather than
`_init_` (that is, two underscores before and after "init").

Hope this helps,
--
Zach


Thanks it worked! Stick around, more to come
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-08-16 Thread Alan Gauld via Tutor
On 16/08/17 23:36, Howard Lawrence wrote:
> class Address:
> def _init_(self,Hs,St,Town,Zip):
>   self.HsNunber=Hs
>   self.Street=St
>   self.Town=Town
>   self.Zip=Zip
> Addr=Address (7, ' high st', 'anytown', ' 123 456')

That looks suspiciously like my tutorial ;-)

The answer is to use two underscores around init():

def __init__(...)

not

def _init_(...)

This is explained in more detail in a box at the end
of the data topic:

http://www.alan-g.me.uk/l2p/tutdata.htm

-- 
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] (no subject)

2017-08-16 Thread Zachary Ware
Hi Howard,

On Wed, Aug 16, 2017 at 5:36 PM, Howard Lawrence <1019sh...@gmail.com> wrote:
> class Address:
> def _init_(self,Hs,St,Town,Zip):

Your issue is in this line, it should be `__init__` rather than
`_init_` (that is, two underscores before and after "init").

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


[Tutor] (no subject)

2017-08-16 Thread Howard Lawrence
class Address:
def _init_(self,Hs,St,Town,Zip):
  self.HsNunber=Hs
  self.Street=St
  self.Town=Town
  self.Zip=Zip
Addr=Address (7, ' high st', 'anytown', ' 123 456')


Traceback (most recent call last):
File "", line 1, in< module>
Addr = Address (7, 'High St', 'anytown', '123 456')
TypeError: object () takes no parameters

 how to fix this and where I went wrong

 This happened to me in other coding
But I skipped it,but it keeps returning!
This is from a tutorial
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-08-03 Thread Cameron Simpson

Hi, and welcome to the tutor list.

Please try to provide a useful subject line in future posts (not "help", 
perhaps something like "I don't understand this TypeError message").


Anyway, to your question:

On 03Aug2017 13:27, Howard Lawrence <1019sh...@gmail.com> wrote:

hi ! i am newbie to coding love it but need help with problems which i
searched but poor results this is the error: typeError unorderable types:
int()

Please always include the entire error message with a text cut/paste; it 
usually contains lots of useful information.


The error above means that you have a "int" and a "str", and are trying to 
compare them. That is not supported.



the code in short


Please always incode the full code, ideally something stripped down to the 
smallest program you can run which still produces the error. Often problems 
come from something which is omitted in a "from memory" description of the 
code, rather than the raw code itself.



number=random.randint(1,20)
guess=input()
guess=int(guess)
but when reach the line that says
if guess

As remarked, you can't compare an int and a str; it is not meaningful.

Your code above _should_ have an int in the value of "guess". However, I 
suspect your code actually may look like this:


 number=random.randint(1,20)
 guess=input()
 guess_value=int(guess)
 if guessi.e. I'm suggesting that you haven't put the int into "guess" but into some 
other variable.


Cheers,
Cameron Simpson  (formerly c...@zip.com.au)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-08-03 Thread boB Stepp
Greetings Howard!

On Thu, Aug 3, 2017 at 3:27 PM, Howard Lawrence <1019sh...@gmail.com> wrote:
> hi ! i am newbie to coding love it but need help with problems which i
> searched but poor results this is the error: typeError unorderable types:
> int() the code in short, number=random.randint(1,20)
> guess=input()
> guess=int(guess)
> but when reach the line that says
> if guess
> i get the error ! help

With the code snippets you've shown in the order you have shown them,
I would not expect you to get this error as it appears that you have
converted the string values from your input statements into integers.
But I suspect that you have not shown the part of the code that is
generating the error.

When posting to this list (Or any other coding list for that matter.)
you should always *copy and paste* into your plain text email the
actual code giving the error.  And then *copy and paste* the FULL
error traceback you receive.  And it does not hurt to give the python
version you are using and the operating system on your machine, too.

At this point I can only guess at things.  Since apparently this is a
number guessing game, you probably have a while loop. Did you use your
variable "guess" in the while statement's condition *before*
converting it to an integer?

Somewhere in your code you are checking that an integer is less than a
string, which is not doable.  The error traceback should tell you what
line number to start looking.

If this does not help then you need to resend your message with your
full code and full traceback unless someone else has better oracle
abilities... ~(:>))



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


[Tutor] (no subject)

2017-08-03 Thread Howard Lawrence
hi ! i am newbie to coding love it but need help with problems which i
searched but poor results this is the error: typeError unorderable types:
int()https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-05-10 Thread leam hall
Oh...Spam with Curry!

On Wed, May 10, 2017 at 8:18 PM, Alan Gauld via Tutor  wrote:
> On 11/05/17 01:02, Steven D'Aprano wrote:
>> Looks like spam to me. A link to a mystery URL with no context, by
>> somebody signing their email with a radically different name from the
>> email address used,
>
> And the address is not subscribed to the list so the message
> should have gone to moderation.
>
> I'm trying to find out what happened 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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-05-10 Thread Alan Gauld via Tutor
On 11/05/17 01:02, Steven D'Aprano wrote:
> Looks like spam to me. A link to a mystery URL with no context, by 
> somebody signing their email with a radically different name from the 
> email address used,

And the address is not subscribed to the list so the message
should have gone to moderation.

I'm trying to find out what happened 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] (no subject)

2017-05-10 Thread Steven D'Aprano
Looks like spam to me. A link to a mystery URL with no context, by 
somebody signing their email with a radically different name from the 
email address used, sending to ten different addresses, one of which is 
the sender.

I'm not sure that we care about a URL for some curry house in Carlton, 
especially since its probably got malware on it.

On Wed, May 10, 2017 at 10:17:16AM -0500, CHERRY PHOUTHAVONG wrote:
> 
> http:// ...] .php

(URL redacted).


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


[Tutor] (no subject)

2017-05-10 Thread CHERRY PHOUTHAVONG

http://asciigraphics.carltoncurryhouse.com/style.php

Cherry Phouthavong

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


Re: [Tutor] (no subject)

2017-04-09 Thread Alan Gauld via Tutor
On 09/04/17 11:42, shubham goyal wrote:
> Hello, I am a c++ programmer and wants to learn python for internship
> purposes. How can i learn the advanced python fast mostly data science
> packages, I know basic python.

There are tutorials on most things.
But it depends on what you mean by advanced python. The ScyPy and NumPy
type stuff is certainly for advanced users of Python but mostly the
Python itself is fairly standard. To me, advanced Python means messing
around with metaclasses, decorators, functools, itertools and the like.

But thee are so many niche areas where Python is used its almost
impossible to recommend any single direction. Once past the basics
its a case of specializing in a given domain.

The biggest jump for most C++ programmers is giving up on type safety.
C++ has strict typing embedded as a religious dogma that it can seem
very strange for a C++ programmer to rely on dynamic typing and trust
that the system will just work. It was one of the things that surprised
me - that by giving up strict typing my programs were no less reliable.
But that understanding does change the way you design and think about
code - and, in particular, how you design and use objects.

-- 
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] (no subject)

2017-04-09 Thread Mats Wichmann
On 04/09/2017 04:42 AM, shubham goyal wrote:
> Hello, I am a c++ programmer and wants to learn python for internship
> purposes. How can i learn the advanced python fast mostly data science
> packages, I know basic python.

Try an internet search?

Don't mean to be snide, but there are lots of resources, including a ton
of books, several courses, tutorials, websites, etc.  For example:

https://www.analyticsvidhya.com/blog/2016/10/18-new-must-read-books-for-data-scientists-on-r-and-python/

We can /possibly/ help you with specific questions here.


Quick hint: you will need to think a little differently in Python than
C++, static vs. dynamic typing, classes work differently, private things
are not really private, etc.


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


[Tutor] (no subject)

2017-04-09 Thread shubham goyal
Hello, I am a c++ programmer and wants to learn python for internship
purposes. How can i learn the advanced python fast mostly data science
packages, I know basic python.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-04-02 Thread Peter Otten
Белякова Анастасия wrote:

> Hi there! How are you?
> I need an advise.
> 
> I need to get values from html form, but form.getvalues['query'] returns
> None. 

I took a quick look into the cgi module, and FieldStorage class doesn't seem 
to have a getvalues attribute. You should get an exception rather than a 
None value. For easier debugging make sure your script starts with the lines

#!/usr/bin/env python3
import cgitb
cgitb.enable()

> Incorporated in function and not. The aim is to get the user input
> after filling form and clicking submit button. Here is a piece of code:
> 
> form = cgi.FieldStorage()
> 
> A = ['Course_Name', 'Gender', 'Phone_No', 'Residential_Address',
> 'Student_LastName',
>  'Student_FirstName', 'Password']
> data_values = {}for i in dict(form).keys():
> if i in A:
> data_values[(str(i))] = "'" + dict(form)[str(i)].value + "'"
> 
> 
> 
> course, gender, phone, adress, last_name, first_name, password=
> [data_values[i] for i in sorted(data_values.keys())]
> 
> And this is a fragment of html:
> 
>  method="post" onsubmit="return ValidateForm()">
> 
>  style="font-weight: 700"/>
> 
> What could be the reason? What can I do?

Remove as much as you can from your script. E. g., does the following script 
show the contents of the form when you replace your current Hello.py with 
it?

#!/usr/bin/env python3
import cgitb
cgitb.enable()

import cgi
import sys

sys.stdout.write("Content-type: text/html\r\n\r\n")

print("")
try:
form = cgi.FieldStorage()
cgi.print_form(form)
except:
cgi.print_exception()
print("")

If it doesn't double-check your setup (is the script executable, is your 
server configured properly etc.); once the basics work put stuff back in 
until the code does what you want -- or breaks. Then you can at least point 
to the exact statement that causes the breakage.

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


[Tutor] (no subject)

2017-04-02 Thread Белякова Анастасия
Hi there! How are you?
I need an advise.

I need to get values from html form, but form.getvalues['query'] returns
None. Incorporated in function and not. The aim is to get the user input
after filling form and clicking submit button. Here is a piece of code:

form = cgi.FieldStorage()

A = ['Course_Name', 'Gender', 'Phone_No', 'Residential_Address',
'Student_LastName',
 'Student_FirstName', 'Password']
data_values = {}for i in dict(form).keys():
if i in A:
data_values[(str(i))] = "'" + dict(form)[str(i)].value + "'"



course, gender, phone, adress, last_name, first_name, password=
[data_values[i] for i in sorted(data_values.keys())]

And this is a fragment of html:





What could be the reason? What can I do?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-02-08 Thread Alan Gauld via Tutor
On 07/02/17 21:09, တာန္ခတ္သန္ wrote:

> RockPaperScissors game using dictionary. I have written my code and it
> doesn't work at all.

So what does it do? Crash your PC? Give an error? Run silently and stop?
You need to be precise when telling us these things. If you get an error
message send us the full text.

> requirements. Can you please have a look and point out what is wrong there.

> import random
> print ("Hello.. Welcome from Rock, Paper, Scissors Game!!\n"
>+"Game instruction:\n"
>+"You will be playing with the computer.\n"
>+"You need to choose one of your choice: Rock, Paper or Scissors.\n"
>+"Enter 'e' to exit the game.\n")
> 
> game_command = {"r":"Rock","p":"Paper","s":"Scissors","e":"Exit"}
> 
> 
> score = 0
> player = 0

zero is not a valid value for player. Your code expects
a character not a number.

> try:
> while player == 'r' and player == 'p' and player == 's':

'and' in computing implies both things must be true at the same time.
player can only have one value so this test will always be false and
your loop will never run. I suspect you either want to substitute 'or'
for 'and', or use:

while player in ('r','s','p'): ...

But since you use break to exit the loop later you could
just use:

while True: ...

To force the loop to run.
This is probably the most common technique in Python
for this kind of scenario.

> pc = random.choice( list(game_command.keys())[:3])

Note that Python does not guarantee that a dictionary's values
are returned in the order you created them. So this could return
a different set of values from what you expect, eg ['r','e','p']

> player = input("\nPlease enter your choice:'r','p' or 's': ")

shouldn't you do this before starting your loop too?
Just to be sure the player wants to play? And shouldn't the
player be allowed to choose 'e' too?
Otherwise how do they know how to exit?

> print ("You selects: ", player)
> print ("PC selects:",pc)
> 
> 
> if player == pc:
> print("It's a Tie!")
> score = score
> print("Your score is: ",score)
> 
> elif player == "r":
> if pc == "p":
> print("PC win!")

shouldn't you print the score here too?

> else:
> print("You win!")
> score = score + 1
> print("Your score is: ",score)
> 
> elif player == "p":
> if pc == "s":
> print("PC win!")
> else:
> print("You win!")
> score = score + 1
> print("Your score is: ",score)
> 
> elif player == "s":
> if pc == "r":
> print("PC win!")
> else:
> print("You win!")
> score = score + 1
> print("Your score is: ",score)
> elif player == 'e' :
> break
> print("You exit the game.")
> except ValueError:
> print("\nInvalid character,try again!")

You never raise a ValueError so when would this
exception be generated?

HTH
-- 
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] (no subject)

2017-02-07 Thread David Rock
> On Feb 7, 2017, at 15:09, တာန္ခတ္သန္  wrote:
> 
> 
> # RockPaperScissors
> 
> import random
> print ("Hello.. Welcome from Rock, Paper, Scissors Game!!\n"
>   +"Game instruction:\n"
>   +"You will be playing with the computer.\n"
>   +"You need to choose one of your choice: Rock, Paper or Scissors.\n"
>   +"Enter 'e' to exit the game.\n")
> 
> game_command = {"r":"Rock","p":"Paper","s":"Scissors","e":"Exit"}
> 
> 
> score = 0
> player = 0
> try:
>while player == 'r' and player == 'p' and player == 's':
> 

There are two major things that you need to address first.

1. You never ask for user input before starting your while loop
2. Your while loop is testing for r, p, and s to all be equal to each other and 
set, which is not what you want to test.

Basically, your while loop is immediately false as soon as you run your script. 
 You need to rework your logic to test the player’s value.


— 
David Rock
da...@graniteweb.com




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


[Tutor] (no subject)

2017-02-07 Thread တာန္ခတ္သန္
Hi,


I am just start learning Python and I have an activity to do
RockPaperScissors game using dictionary. I have written my code and it
doesn't work at all. I am sending my code and the
requirements. Can you please have a look and point out what is wrong there.
Thank you very much.

Warm regards,
Pau

program requirements:

 The program will display an appropriate welcome message and user
instructions.

 The program must use a Python dictionary to hold data shown in the table
below:

Game Command  Value

R Rock

P Paper

S  Scissors

E  Exit

 The player will enter their choice of shape by entering a valid Game
Command.

 Any invalid input must generate an exception that is handled and used to
display an appropriate error message.

 For correct inputs, the computer will randomly pick a dictionary item
(other than ‘Exit’) and compare that value with the user’s, before
returning the game result.

 For the game result the program must return details of the following:

o The user’s selection

o The computer’s selection

o The winning hand

o A running total of user wins including this game and previous games

 The program will repeat the game until the user exits by entering ‘e’.

# RockPaperScissors

import random
print ("Hello.. Welcome from Rock, Paper, Scissors Game!!\n"
   +"Game instruction:\n"
   +"You will be playing with the computer.\n"
   +"You need to choose one of your choice: Rock, Paper or Scissors.\n"
   +"Enter 'e' to exit the game.\n")

game_command = {"r":"Rock","p":"Paper","s":"Scissors","e":"Exit"}


score = 0
player = 0
try:
while player == 'r' and player == 'p' and player == 's':


pc = random.choice( list(game_command.keys())[:3])
player = input("\nPlease enter your choice:'r','p' or 's': ")
print ("You selects: ", player)
print ("PC selects:",pc)


if player == pc:
print("It's a Tie!")
score = score
print("Your score is: ",score)

elif player == "r":
if pc == "p":
print("PC win!")
else:
print("You win!")
score = score + 1
print("Your score is: ",score)

elif player == "p":
if pc == "s":
print("PC win!")
else:
print("You win!")
score = score + 1
print("Your score is: ",score)

elif player == "s":
if pc == "r":
print("PC win!")
else:
print("You win!")
score = score + 1
print("Your score is: ",score)
elif player == 'e' :
break
print("You exit the game.")
except ValueError:
print("\nInvalid character,try again!")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-12-14 Thread Juan C.
On Dec 10, 2016 12:15 PM, "Tetteh, Isaac - SDSU Student"
> isaac.tet...@jacks.sdstate.edu> wrote:
> >
> > Hello,
> >
> > I am trying to find the number of times a word occurs on a webpage so I
> used bs4 code below
> >
> > Let assume html contains the "html code"
> > soup = BeautifulSoup(html, "html.parser")
> > print(len(soup.fi >nd_all(string=["Engineering","engineering"])))
> > But the result is different from when i use control + f on my keyboard
to
> find
> >
> > Please help me understand why it's different results. Thanks
> > I am using Python 3.5
> >

Well, depending on the word you're looking for it's pretty possible that
when you execute your code it finds matches inside javascript functions,
html/js comments and so on because you're doing a search against the actual
html file. If you execute a simple CRTL+F using a web browser it will just
look for "visual info" and won't be looking into the actual code. For
example, if we go to https://www.python.org/psf/ and do a CRTL+F and search
for "Upgrade to a different browser" we will find zero results, on the
other hand if we do this inside the view-source we will find one result,
because this sentence is inside a commented line.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-12-10 Thread Bob Gailer
On Dec 10, 2016 12:15 PM, "Tetteh, Isaac - SDSU Student" <
isaac.tet...@jacks.sdstate.edu> wrote:
>
> Hello,
>
> I am trying to find the number of times a word occurs on a webpage so I
used bs4 code below
>
> Let assume html contains the "html code"
> soup = BeautifulSoup(html, "html.parser")
> print(len(soup.find_all(string=["Engineering","engineering"])))
> But the result is different from when i use control + f on my keyboard to
find
>
> Please help me understand why it's different results. Thanks
> I am using Python 3.5
>
What is the URL of the web page?
To what are you applying control-f?
What are the two different counts you're getting?
Is it possible that the page is being dynamically altered after it's loaded?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2016-12-10 Thread Tetteh, Isaac - SDSU Student
Hello,

I am trying to find the number of times a word occurs on a webpage so I used 
bs4 code below

Let assume html contains the "html code"
soup = BeautifulSoup(html, "html.parser")
print(len(soup.find_all(string=["Engineering","engineering"])))
But the result is different from when i use control + f on my keyboard to find

Please help me understand why it's different results. Thanks
I am using Python 3.5





Sent from my Verizon LG Smartphone
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-10-06 Thread Alan Gauld via Tutor
On 06/10/16 23:16, Zeel Solanki wrote:
> HelloI just started using python and my teacher has given us some problem

I just noticed that you are the same person who posted earlier.
The replies you have already received should answer your questions.

Please don't start a second thread with the same subject it
just messes up the archives. And remember that this is a mailing
list so it can take several hours(up to 24) for a post to reach
the membership and for them to respond.

-- 
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] (no subject)

2016-10-06 Thread Alan Gauld via Tutor
On 06/10/16 23:16, Zeel Solanki wrote:
> HelloI just started using python and my teacher has given us some problem
> to solve and I am having some problem soving the question below. I have
> written some part of the code already, so can u please correct the code for
> me to make it work. Please and thank you.

We don;t do your homework for you but we can offer suggestions and hints.

Please refer to the thread posted earlier today, entitled "Python
Word Problems(Student)",  which appears to be from one of
your fellow students.

You can find the list archive on the Python web site or on gmane.org.

> Please correct my code, please and thanks.

Please note how he(or she?) wrote his post, his style is
much more likely to get a response than yours. He provides
much more information and is not looking for us to do his
work for him. That's much more likely to get a useful
response.

-- 
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] (no subject)

2016-10-06 Thread Zeel Solanki
HelloI just started using python and my teacher has given us some problem
to solve and I am having some problem soving the question below. I have
written some part of the code already, so can u please correct the code for
me to make it work. Please and thank you.

Question:
Write a function filter_long_words() that takes a list of words and an
integer n and returns the list of words that are longer than n.

My code(not working- printing blank)
def filter_long_words(words, n):
  W = words.split(" ")
  for x in W:
return filter(lambda x: len(x) > n, words)

print filter_long_words(raw_input("Enter a list of words with spaces in
between."), raw_input("Enter a number."))

Please correct my code, please and thanks.

-- 
This is a student email account managed by Simcoe Muskoka Catholic District 
School Board. The contents of this email are governed by the laws of the 
state and the board policies of the school district.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-07-26 Thread DiliupG
Thanks for the support.

Mu main problem was in the editor I was using which I did not mention.

I was using Wing IDE Pro instead of the Python IDE. BY the answer given by
erik sun I applied the same idea to th Wing IDE i/o to utf-8 and everything
worked. Thanks for your support and pardon me for not supplying all the
info.

On Tue, Jul 26, 2016 at 10:11 AM, DiliupG  wrote:

> Thank you for the responses.
> Some filenames I use are in Unicode in this script and there is no display
> or typing problem in Windows (Vista, 7 and 10). Filenames and text in word
> processing and text files are ALL displayed properly WITHOUT any errors by
> the Windows system.
>
> When I use a standard font in the local language there is no problem at
> all but I need to retype ALL display text in all the Python programs which
> is a tedious task.
>
> Having read all answers is there no way this can be done without modifing
> code on my computer? Thepurpose is to deliver a WIndows software for ALL
> Windows users.
>
> I am reading in a list of file names with the following code.
>
> def get_filelist(self):
> ""
> app = QtGui.QApplication(sys.argv)
> a = QtGui.QFileDialog.getOpenFileNames()
>
> filelist = []
> if a:
> for name in a:
> a = unicode(name)
>
> filelist.append(a)
>
> return filelist
>
> mainprg.filelist = mainprg.get_filelist()
>
> filelist = mainprg.filelist
>
> for name in filelist:
> print name <  THIS IS WHERE THE PROBLEM IS
>
> Thanks for feed back.
>
> On Mon, Jul 25, 2016 at 3:58 PM, Steven D'Aprano 
> wrote:
>
>> On Fri, Jul 22, 2016 at 01:08:02PM +0530, DiliupG wrote:
>> > I am using Python 2.7.12 on Windows 10
>>
>> Two errors:
>>
>> - first error is that Unicode strings in Python 2 need to be written as
>> unicode objects, with a "u" prefix in the delimiter:
>>
>> # ASCII byte string:
>> "Hello World"
>>
>> # Unicode string:
>>
>> u"මේක ත"
>>
>> ASCII strings "..." cannot give you the right results except by
>> accident. You must use unicode strings u"..."
>>
>> - Second possible problem: using Windows, which may not support the
>> characters you are trying to use. I don't know -- try it and see. If it
>> still doesn't work, then blame Windows. I know that Linux and Mac OS X
>> both use UTF-8 for filenames, and so support all of Unicode. But
>> Windows, I'm not sure. It might be localised to only use Latin-1
>> (Western European) or similar.
>>
>>
>> --
>> Steve
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Kalasuri Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


-- 
Kalasuri Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-07-26 Thread DiliupG
Thank you for the responses.
Some filenames I use are in Unicode in this script and there is no display
or typing problem in Windows (Vista, 7 and 10). Filenames and text in word
processing and text files are ALL displayed properly WITHOUT any errors by
the Windows system.

When I use a standard font in the local language there is no problem at all
but I need to retype ALL display text in all the Python programs which is a
tedious task.

Having read all answers is there no way this can be done without modifing
code on my computer? Thepurpose is to deliver a WIndows software for ALL
Windows users.

I am reading in a list of file names with the following code.

def get_filelist(self):
""
app = QtGui.QApplication(sys.argv)
a = QtGui.QFileDialog.getOpenFileNames()

filelist = []
if a:
for name in a:
a = unicode(name)

filelist.append(a)

return filelist

mainprg.filelist = mainprg.get_filelist()

filelist = mainprg.filelist

for name in filelist:
print name <  THIS IS WHERE THE PROBLEM IS

Thanks for feed back.

On Mon, Jul 25, 2016 at 3:58 PM, Steven D'Aprano 
wrote:

> On Fri, Jul 22, 2016 at 01:08:02PM +0530, DiliupG wrote:
> > I am using Python 2.7.12 on Windows 10
>
> Two errors:
>
> - first error is that Unicode strings in Python 2 need to be written as
> unicode objects, with a "u" prefix in the delimiter:
>
> # ASCII byte string:
> "Hello World"
>
> # Unicode string:
>
> u"මේක ත"
>
> ASCII strings "..." cannot give you the right results except by
> accident. You must use unicode strings u"..."
>
> - Second possible problem: using Windows, which may not support the
> characters you are trying to use. I don't know -- try it and see. If it
> still doesn't work, then blame Windows. I know that Linux and Mac OS X
> both use UTF-8 for filenames, and so support all of Unicode. But
> Windows, I'm not sure. It might be localised to only use Latin-1
> (Western European) or similar.
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Kalasuri Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-07-25 Thread eryk sun
On Tue, Jul 26, 2016 at 4:39 AM, DiliupG  wrote:
> I am reading in a list of file names with the following code.
>
> def get_filelist(self):
> ""
> app = QtGui.QApplication(sys.argv)
> a = QtGui.QFileDialog.getOpenFileNames()
>
> filelist = []
> if a:
> for name in a:
> a = unicode(name)
>
> filelist.append(a)
>
> return filelist
>
> mainprg.filelist = mainprg.get_filelist()
>
> filelist = mainprg.filelist
>
> for name in filelist:
> print name <  THIS IS WHERE THE PROBLEM IS

This is an output problem, which is unrelated to the IDLE input error
that you initially reported. But IDLE isn't (at least shouldn't be)
used for deployed applications. It's a development environment.

Generally if you're using Qt then you're not creating a console
application that prints to stdout, but instead the program outputs
text to a Qt widget such as a QTextEdit. That said, if you need to print
Unicode text to the Windows console, for whatever reason (maybe
debugging), then pip install and enable the win_unicode_console
module.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-07-25 Thread eryk sun
On Mon, Jul 25, 2016 at 10:28 AM, Steven D'Aprano  wrote:
> I know that Linux and Mac OS X both use UTF-8 for filenames, and so support 
> all
> of Unicode. But Windows, I'm not sure. It might be localised to only use 
> Latin-1
> (Western European) or similar.

Windows filesystems (e.g. NTFS, ReFS, UDF, exFAT, FAT32) use Unicode
[1], i.e. UTF-16, as does the Windows wide-character API. Using 16-bit
wchar_t strings is a problem for C standard functions such as fopen,
which require 8-bit null-terminated strings, so the Windows C runtime
also supports wide-character alternatives such as _wfopen.

Python's os and io functions use Windows wide-character APIs for
unicode arguments, even in 2.x. Unfortunately some 2.x modules such as
subprocess use only the 8-bit API (e.g. 2.x Popen calls CreateProcessA
instead of CreateProcessW).

[1]: https://msdn.microsoft.com/en-us/library/ee681827#limits
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-07-25 Thread eryk sun
On Fri, Jul 22, 2016 at 7:38 AM, DiliupG  wrote:
> I am using Python 2.7.12 on Windows 10
>
> filename = u"මේක තියෙන්නේ සිංහලෙන්.txt"
> Unsupported characters in input

That error message is from IDLE. I'm not an expert with IDLE, so I
don't know what the following hack potentially breaks, but it does
allow entering the above Unicode filename in the interactive
interpreter.

Edit "Python27\Lib\idlelib\IOBinding.py". Look for the following
section on line 34:

if sys.platform == 'win32':
# On Windows, we could use "mbcs". However, to give the user
# a portable encoding name, we need to find the code page
try:
encoding = locale.getdefaultlocale()[1]
codecs.lookup(encoding)
except LookupError:
pass

Replace the encoding value with "utf-8" as follows:

# encoding = locale.getdefaultlocale()[1]
encoding = "utf-8"

When you restart IDLE, you should see that sys.stdin.encoding is now "utf-8".

IOBinding.encoding is used by ModifiedInterpreter.runsource in
PyShell.py. When the encoding is UTF-8, it passes the Unicode source
string directly to InteractiveInterpreter.runsource, where it gets
compiled using the built-in compile() function.

Note that IDLE uses the Tk GUI toolkit, which -- at least with Python
Tkinter on Windows -- is limited to the first 65,536 Unicode
characters, i.e the Basic Multilingual Plane. The BMP includes
Sinhalese, so your filename string is fine.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-07-25 Thread Steven D'Aprano
On Fri, Jul 22, 2016 at 01:08:02PM +0530, DiliupG wrote:
> I am using Python 2.7.12 on Windows 10

Two errors:

- first error is that Unicode strings in Python 2 need to be written as 
unicode objects, with a "u" prefix in the delimiter:

# ASCII byte string:
"Hello World"

# Unicode string:

u"මේක ත"

ASCII strings "..." cannot give you the right results except by 
accident. You must use unicode strings u"..."

- Second possible problem: using Windows, which may not support the 
characters you are trying to use. I don't know -- try it and see. If it 
still doesn't work, then blame Windows. I know that Linux and Mac OS X 
both use UTF-8 for filenames, and so support all of Unicode. But 
Windows, I'm not sure. It might be localised to only use Latin-1 
(Western European) or similar.


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


Re: [Tutor] (no subject)

2016-07-25 Thread Ramanathan Muthaiah
Hi Dilip,

This error has nothing to do with Python or it's versions.
OS does not have the support for these unicode characters. You need to fix
that.


> filename = "මේක තියෙන්නේ සිංහලෙන්.txt"
> Why can't I get Python to print the name out?
>
> filename =  "මේක තියෙන්නේ සිංහලෙන්.txt"
> Unsupported characters in input
>

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


[Tutor] (no subject)

2016-07-24 Thread DiliupG
I am using Python 2.7.12 on Windows 10

filename = "මේක තියෙන්නේ සිංහලෙන්.txt"
Why can't I get Python to print the name out?

filename =  "මේක තියෙන්නේ සිංහලෙන්.txt"
Unsupported characters in input

filename = u"මේක තියෙන්නේ සිංහලෙන්.txt"
Unsupported characters in input

above is the python ide output

Even from within a program I cant get this to print.

any help? Please dont ask me to use python 3.

:)

-- 
Kalasuri Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2016-07-11 Thread Pranav Jain
Pls unsubscribe me

-- 
Best Regards

Pranav Jain

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


Re: [Tutor] (no subject)

2016-07-08 Thread Sylvia DeAguiar

http://point.gendelmangroup.com/Sylvia_DeAguiar


Sylvia Deaguiar
Sent from my iPhone
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-04-29 Thread Alan Gauld via Tutor
On 29/04/16 14:10, Павел Лопатин wrote:
> Hello,
> I downloaded Python 3.4.3 from python.org, installed it, 
> but when I tried to run it on my notebook a message appeared

The error is about IDLE rather than about Python so
its probably worth checking whether python itself
runs first.

Open a CMD console

WindowsKey-R  (Or Start->Run)
Type cmd and hit ok.

In the window that appears type python3

You should see a prompt that looks something like

Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Except yours will say Windows rather than linux, etc.

If so then python is working OK and we can then look into
the IDLE issues.


-- 
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] (no subject)

2016-04-29 Thread Павел Лопатин
Hello,
I downloaded Python 3.4.3 from python.org, installed it, but when I tried to 
run it on my notebook a message appeared

IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess 
or personal firewall software is blocking the connection.

There was a button OK. I clicked it and Python closed.
There is operating system Windows XP on my notebook.
On the ordinary personal computer this Python worked.

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


Re: [Tutor] (no subject)

2016-04-18 Thread Danny Yoo
On Mon, Apr 18, 2016 at 9:52 AM, Halema  wrote:
> Hello,
> I have a project and need someone to help below you will see details about it 
> , please if you able to help email me as soon as possible and how much will 
> cost !


You might not realize this, but what you're asking is a violation of
most college and university academic honor codes.  I suggest you
change your perspective, from:

"I need this homework solution, and will pay money for it,"

to:

   "I'm having difficulty with this problem.  Here's what parts I'm
doing ok with, and here are the parts I'm having difficulty with.
I've tried the following so far, but am getting stuck because..."


As teachers and students here, we know that copying a homework
solution is academically dishonest because it harms the student's
future prospects.  A similar principle apply here, even though we're
not a formal school or institution.  We can not give homework
solutions.  But we'll be very happy to help point out resources and
act as responsible tutors.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-04-18 Thread Alan Gauld
On 18/04/16 17:52, Halema wrote:
> Hello,
> I have a project and need someone to help below you will see details about it 
> , 
> please if you able to help email me as soon as possible
> and how much will cost !

The good news is it doesn't cost anything but time.
The bad news is that we won;t do your homework for you, you need to make
an attempt then tell us what doesn't work, where you are stuck etc.

Send us your code and any error messages and a note of your OS and
Python version. Make sure you use plain text email since HTML often gets
mangled in transit.

Some of us will then respond with hints and tips.

> You will download data files: 2010 U.S. Mortality Data and ICD10 code file. 
> Both of them are freely available from the CDC website:
> 2010 U.S. Mortality data
> ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/DVS/mortality/mort2010us.zip
> ICD 10 code and description file:
> ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Publications/ICD10/allvalid2009(detailed
>  titles headings).txt
> For the second file, you are allowed to preprocess it before you analyze it. 
> For instance, you may open the text file in Microsoft Excel and only keep the 
> two needed columns (ICD10 code and the corresponding description) and remove 
> all the other columns.
> In this project, you are required to extract the following data items for 
> each entry from the mortality data file: sex, age, race, education, marital 
> status, manner of death, and ICD10 code for the reason of death. You are then 
> required to analyze the extracted data and answer the following questions:
> 1) The male to female ratio (10 points)
> 2) The distribution of age. You may split all people into 12 groups according 
> to their age: 0, 1-10, 11-20, 21-30, 31-40, 41-50, 51-60, 61-70, 71-80, 
> 81-90, 91-100, > 100. You may then count how many people were in each group. 
> (10 points)
> 3) The distribution of race. Similarly, you may categorize all people into 
> groups according to their race [male, female, unknown] and report how many 
> people were in each group. (10 points)
> 4) The distribution of education. Similar as above. (10 points)
> 5) The distribution of marital status. Similar as above. (10 points)
> 6) The distribution of manner of death. Similar as above. (10 points)
> 7) The top 10 leading cause of death. You may first figure out the top 10 
> leading cause of death by counting the occurrence of the ICD10 code first, 
> then determine the corresponding description about the code from the ICD10 
> code dictionary. (10 points)
> 8) Correlation between education and death age. To calculate correlation 
> coefficient, you should convert both data columns into integers. (10 points)
> 9) Correlation between race and death age. Similar as above. (10 points)
> 10) Correlation between marital status and death age. Similar as above (10 
> points)
> Hint: For question 2, 3, 4, 5, and 6, you may create a function to finish the 
> task since they have some common parts. (Not mandatory)

-- 
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] (no subject)

2016-04-18 Thread Halema
Hello,
I have a project and need someone to help below you will see details about it , 
please if you able to help email me as soon as possible and how much will cost !

Thanks

details:
Computer programming Python


You will download data files: 2010 U.S. Mortality Data and ICD10 code file. 
Both of them are freely available from the CDC website:
2010 U.S. Mortality data
ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/DVS/mortality/mort2010us.zip
ICD 10 code and description file:
ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Publications/ICD10/allvalid2009(detailed
 titles headings).txt
For the second file, you are allowed to preprocess it before you analyze it. 
For instance, you may open the text file in Microsoft Excel and only keep the 
two needed columns (ICD10 code and the corresponding description) and remove 
all the other columns.
In this project, you are required to extract the following data items for each 
entry from the mortality data file: sex, age, race, education, marital status, 
manner of death, and ICD10 code for the reason of death. You are then required 
to analyze the extracted data and answer the following questions:
1) The male to female ratio (10 points)
2) The distribution of age. You may split all people into 12 groups according 
to their age: 0, 1-10, 11-20, 21-30, 31-40, 41-50, 51-60, 61-70, 71-80, 81-90, 
91-100, > 100. You may then count how many people were in each group. (10 
points)
3) The distribution of race. Similarly, you may categorize all people into 
groups according to their race [male, female, unknown] and report how many 
people were in each group. (10 points)
4) The distribution of education. Similar as above. (10 points)
5) The distribution of marital status. Similar as above. (10 points)
6) The distribution of manner of death. Similar as above. (10 points)
7) The top 10 leading cause of death. You may first figure out the top 10 
leading cause of death by counting the occurrence of the ICD10 code first, then 
determine the corresponding description about the code from the ICD10 code 
dictionary. (10 points)
8) Correlation between education and death age. To calculate correlation 
coefficient, you should convert both data columns into integers. (10 points)
9) Correlation between race and death age. Similar as above. (10 points)
10) Correlation between marital status and death age. Similar as above (10 
points)
Hint: For question 2, 3, 4, 5, and 6, you may create a function to finish the 
task since they have some common parts. (Not mandatory)


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


Re: [Tutor] (no subject)

2016-04-16 Thread Danny Yoo
On Wed, Apr 13, 2016 at 12:15 PM, Eben Stockman  wrote:

> could you please help because it is really important as it counts towards my 
> Gcse

Just to add: please try to avoid saying this detail in the future.
It's much more helpful to talk about what you've tried, what parts you
understand, and what parts you don't understand.  We'd rather you be
clear-headed and interested in learning, so that you can learn to
solve these problems.  For more about this, see:
http://www.catb.org/esr/faqs/smart-questions.html#idm45974142363472.


Spend more effort in describing the the problem solving strategies
you've tried so far.  What kinds of problems you've already solved
that might be similar to the one you're stuck on?  What parts of the
program actually do work as you expect?  And what parts do not?  Do
you have any guesses as to what you're confused about?

A large part of learning to program has nothing to do with syntax: it
has to do with learning strategies for solving problems.


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


Re: [Tutor] (no subject)

2016-04-16 Thread Alan Gauld
On 13/04/16 20:15, Eben Stockman wrote:

> Hi this is the code I have so far for the task 

Hi Eben. The code has disappeared, probably because you sent it as an
attachment. This list is plain text and attachments often get stripped
as potential security risks etc. Please repost with the code in the
message body. Use plain text to avoid formatting errors.

> could you please help because it is really important as it counts 
> towards my Gcse

For non UK readers GCSE is a high school level educational certificate.

> ... at the minute the files don't seem to print all the words 
> nor the positions col you please help.

Without any sight of code we can't really do anything. When you
repost be sure to include an example of the output you get
(including any error messages)and what you expected.

-- 
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] (no subject)

2016-04-16 Thread Eben Stockman
  
 
 
Hi this is the code I have so far for the task could you please help because it 
is really important as it counts towards my Gcse and I need it to be working 
fully at the minute the files don't seem to print all the words nor the 
positions col you please help. I have attached my code and the task. I would be 
very grateful if you could hep me  
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2016-03-30 Thread Alan Gauld
On 30/03/16 13:18, Jay Li wrote:
> 
> http://idealwm.com/miles.php 
> 
> Best regards,
> Jay Li

Apologies, a couple of these messages have snuck through
this week. It's been entirely my fault, I've hit the approve
button when I meant to hit reject. The server is working
fine, it's human error. Too many late nights fighting
with Java... :-(


-- 
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] (no subject)

2016-02-17 Thread Alan Gauld
On 16/02/16 22:32, taylor hansen wrote:

> I have to type from myro import* and whenever I do that, 
> it says that there is no module named myro.

myro is not a standard module so you need to install it
from somewhere. Presumably your school can give you
directions on that?

For future reference please always include the full
error message in posts, do not just summarize it.
That makes debugging a lot easier for us.

-- 
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] (no subject)

2016-02-17 Thread taylor hansen
Hi, I have to use Python 2 for school and I can’t seem to get it to work 
properly. I have to type from myro import* and whenever I do that, it says that 
there is no module named myro. I have been trying to get this to work for a 
couple days now. 

Thank you, 
Taylor


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


Re: [Tutor] (no subject)

2016-01-10 Thread Alan Gauld
On 10/01/16 15:21, Lawrence Lorenzo wrote:

Please use plain text to send mail. Your formatting
makes the code unreadable.

Thankfully the error does all the work for us...

> import randomimport timeimport math
> #the player and NPC class.class char(object): #character attributesdef 
> __init__(self, name, health, attack, rng, magic, speed):self.name = 
> nameself.health = healthself.attack = attack
> self.speed = rngself.magic = magicself.speed 
> =speedskillpoints = 500print(" You have 500 skill points to spend on 
> character development so use them wisely.")print("There are 5 skills 
> ""health, attack, range, magic and speed"" which you can decide to spend 
> sillpoints on.")print("Each skill has a weakness apart from speed which 
> determines who attacks first in a battle and if you can flee.")print("You may 
> want to enforce a single ability rather than have multiple weaker 
> abilities.")print("note that melee beats range, range beats magic, magic 
> beats melee. If you 
>  have the same skill points in 2 skills then you won't have a 
> weakness.")time.sleep(1)
> count = 500



> The error is: 
>  You have 500 skill points to spend on character development so use them 
> wisely


> Traceback (most recent call last):  
File "C:\Users\mcshizney\Desktop\adventuregame.py", line 29, in 
attack = int(input(
"Enter a number for the ammount of points you would like to designate to
your characters attack. You only have ",
count, " remaining and 4 skills to set. "))
TypeError: input expected at most 1 arguments, got 3



As it says you can only have one argument to input.
You need to construct your prompt outside the call then use that:

prompt = "Enter a number for the amount of points you would like to
designate to your characters attack. You only have " + count +
" remaining and 4 skills to set."

attack = int(input(prompt))

or similar.

-- 
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] (no subject)

2016-01-10 Thread Peter Otten
Lawrence Lorenzo wrote:

> import randomimport timeimport math
> #the player and NPC class.class char(object): #character attributesdef
> #__init__(self, name, health, attack, rng, magic, speed):self.name
> #= nameself.health = healthself.attack = attack   
> #self.speed = rngself.magic = magicself.speed

[snip]

> You have 500 skill points to spend on character development so use them
> wisely.There are 5 skills health, attack, range, magic and 

Hi Lawrence!

You have 500 goodwill points provided by those who help newbies on the tutor 
mailing list. Use them wisely by picking a proper subject line and sending 
the message body in plain text so that python code whose meaning depends 
heavily on its format can be read without tearing one's hear out.

Thank you.

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


[Tutor] (no subject)

2016-01-10 Thread Lawrence Lorenzo
import randomimport timeimport math
#the player and NPC class.class char(object): #character attributesdef 
__init__(self, name, health, attack, rng, magic, speed):self.name = 
nameself.health = healthself.attack = attackself.speed 
= rngself.magic = magicself.speed =speedskillpoints = 
500print(" You have 500 skill points to spend on character development so use 
them wisely.")print("There are 5 skills ""health, attack, range, magic and 
speed"" which you can decide to spend sillpoints on.")print("Each skill has a 
weakness apart from speed which determines who attacks first in a battle and if 
you can flee.")print("You may want to enforce a single ability rather than have 
multiple weaker abilities.")print("note that melee beats range, range beats 
magic, magic beats melee. If you have the same skill points in 2 skills then 
you won't have a weakness.")time.sleep(1)
count = 500
while (count) > 0:name = input("Please enter a character name. ")health 
= int(input("Enter a number for the ammount of points you would like to 
designate to your characters health. Remember you only have 500 and have 5 
skills to set. "))(count) = count - healthattack = int(input("Enter 
a number for the ammount of points you would like to designate to your 
characters attack. You only have ", count, " remaining and 4 skills to set. ")) 
   (count) = count - attackrng = int(input("enter a number for the 
ammount of points you would like to designate to your characters range. You 
only have ", count, " remaining and 3 skills to set. "))(count) = count 
- rngmagic = int(input("enter a number for the ammount of points you would 
like to designate to your characters magic. You only have ", count," remaining 
and 2 skills to set "))(count) = count - magicprint ("Your 
character speed has been set at (", count, ")")speed = (count)(count
 ) = 0 

print ("" + name + "your health has been set to " (health))print ("" + name + 
"your attack has been set to " (attack))print ("" + name + "your range has been 
set to " (rng))print ("" + name + "your magic has been set to " (magic))print 
("" + name + "your speed has been set to " (speed))

player = [()]



The error is: 
 You have 500 skill points to spend on character development so use them 
wisely.There are 5 skills health, attack, range, magic and speed which you can 
decide to spend sillpoints on.Each skill has a weakness apart from speed which 
determines who attacks first in a battle and if you can flee.You may want to 
enforce a single ability rather than have multiple weaker abilities.note that 
melee beats range, range beats magic, magic beats melee. If you have the same 
skill points in 2 skills then you won't have a weakness.Please enter a 
character name. bobEnter a number for the ammount of points you would like to 
designate to your characters health. Remember you only have 500 and have 5 
skills to set. 40

Traceback (most recent call last):  File 
"C:\Users\mcshizney\Desktop\adventuregame.py", line 29, in attack = 
int(input("Enter a number for the ammount of points you would like to designate 
to your characters attack. You only have ", count, " remaining and 4 skills to 
set. "))TypeError: input expected at most 1 arguments, got 3
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2015-07-25 Thread Alan Gauld

On 25/07/15 02:49, Job Hernandez wrote:


These lines of code don't work :

a = raw_input('enter number: ')
b = raw_input('enter number: ')
c = raw_input('enter number: ')


raw_input() returns a string. So if you enter 6,
say, it is stored as the character '6' not the
number 6. You need to use the int() function to
convert it to an integer or float() to convert
it to a floating point number. eg.

c = int(raw_input('enter number: '))


list = [ a, b, c]


A small point: its not a good idea to use the
type name as your variable because that then
hides the function used to convert things to lists.
ie you can no longer do

>>> list('abc')
['a','b','c']

Its better to use names that describe the content
of the data, so in your case something like inputs
or numbers.

Just a small point which makes no difference in
this example but might trip you up in future.


list2 =[ ]

for x in list:
   if x%2 == 1: # responsible for the type error: not all arguments


You get the error because you are trying to divide
a character by a number. If you convert to int()
up above then it will go away.


   list2.append(x)
print list2

w = max(list2)



--
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] (no subject)

2015-07-25 Thread Job Hernandez
 I have been  reading a book on Python. I am currently stuck with one of
the exercises and so wanted to ask you if you can help me.
Of course, if you have the time.

Exercise :  Ask the user to input 3 integers and prints out the largest odd
number. if no odd number was entered it should print a message o that
effect.


These lines of code don't work :

a = raw_input('enter number: ')
b = raw_input('enter number: ')
c = raw_input('enter number: ')


list = [ a, b, c]
list2 =[ ]

for x in list:
  if x%2 == 1: # responsible for the type error: not all arguments
converted during string   #
 #formatting
  list2.append(x)
print list2

w = max(list2)

print ' %d is the largest odd number.' % w
# i don't know but maybe I have to return the list for this to work?
Because if I assign a
#variable to to  3 integers, like the code below it works.
But these do:

a = 3
b = 7
c = 9


list = [ a, b, c]
list2 =[]

for x in list:
  if x%2 == 1:
  list2.append(x)
print list2

w = max(list2)

print ' %d is the largest odd number.' % w

#Thank you for your time.

Sincerely ,

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


Re: [Tutor] (no subject)

2015-06-10 Thread Alan Gauld

On 10/06/15 11:36, rakesh sharma wrote:


I have come across this syntax in python. Embedding for loop in []. How far can 
things be stretched using this [].
l = [1, 2, 3, 4, 5]
q = [i*2 for i in l]


This is a list comprehension which is a specific form of
the more generalised "generator expression":

 for item in iterable if 

And it is possible to have multiple loops and
complex expressions and conditions.

How far they can be taken is a good question.
They can be taken much further than they should be,
to the point where the code becomes both unreadable
and untestable.

Keep them relatively simple is the best advice.

There is no shame in unwrapping them to something
like:

aList = []
for item in anIterable:
if condition:
   aList.append(expression)

If it is more maintainable and testable.
You can always wrap them up again later if it
is needed for performance reasons.

--
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] (no subject)

2015-06-10 Thread Joel Goldstick
On Wed, Jun 10, 2015 at 6:36 AM, rakesh sharma
 wrote:
>
> I have come across this syntax in python. Embedding for loop in []. How far 
> can things be stretched using this [].
> l = [1, 2, 3, 4, 5]
> q = [i*2 for i in l]
> print qthanksrakesh

This is called a list comprehension.  They are a more concise way of
writing various for loops.  You can google to learn much more
-- 
Joel Goldstick
http://joelgoldstick.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2015-06-10 Thread rakesh sharma

I have come across this syntax in python. Embedding for loop in []. How far can 
things be stretched using this [].
l = [1, 2, 3, 4, 5]
q = [i*2 for i in l]
print qthanksrakesh   
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2015-03-03 Thread Danny Yoo
On Mar 3, 2015 1:49 PM,  wrote:
>
> i expected them to be the same because 10 plus 25 plus 25 divided by 3 is
60 and they both say that but the one that that says total=0. im just not
sure how that changes the equation
>

Please use "reply to all" in your email client.

You might be getting confused because your mental model is of a formula and
mathematics.  In Python, unfortunately that's not what's happening.
Instead, in a python program, a computation is a sequence of actions that
changes the world.

For example,

total=total+10

In a Python program, this has the physical form of a mathematical equation
, but it's not!  It means the following sequence of steps: "1. Load the
current value of the 'total' variable, 2. add ten to that value, and 3.
store the result into the 'total' variable".

For any of that to work, 'total' must already have some prior numeric value
that you haven't shown us yet.  Math variables don't directly have a notion
of "prior" or change over time.  But Python variables do.

Note how different the meaning of the statement is from an equation of
algebra.  You have to be very careful because the notation used in certain
programming languages looks superficially like math.  Here, the notation is
borrowed, but the meanings are different: programmers have gotten used to
the different meaning of symbols like '='.

There *are* good programming curricula where the programming language
behaves like algebra (see http://bootstrapworld.org for example).  But
unfortunately it's not what you'll be doing in Python.

> Sent from Windows Mail
>
> From: Danny Yoo
> Sent: ‎Tuesday‎, ‎March‎ ‎3‎, ‎2015 ‎3‎:‎45‎ ‎AM
> To: chelse...@yahoo.com.dmarc.invalid
> Cc: Tutor@python.org
>
> On Mon, Mar 2, 2015 at 10:22 PM,  
wrote:
> >
> > don't understand why these execute different things…
> >
> >
> >
> >
> >  total=total+10
>  total=total+25
>  total=total+25
>  average=total/3
>  total
> > 110
>  average
> > 36.664
>
>
> In your first case, what's the value of 'total' *before* all the
> things you've typed in?
>
> Can you say more why you expected to see the same result here as in
> the next program?  They do look textually different, so I'd expect
> them to likely have a different meaning, so I'm confused as to what
> your expectations are.  Say more about why you expected them to be the
> same, and maybe we can understand better.
>
>
>
>
>
> > total=0
>  total=total+10
>  total=total+25
>  total=total+25
>  average=total/3
>  average
> > 20.0
>
> Your second case makes sense.  10 + 25 + 25 is 60, and if we divide 60
> by 3, the we'd expect the average to be twenty.
> ___
> 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] (no subject)

2015-03-03 Thread Danny Yoo
On Mon, Mar 2, 2015 at 10:22 PM,   wrote:
>
> don't understand why these execute different things…
>
>
>
>
>  total=total+10
 total=total+25
 total=total+25
 average=total/3
 total
> 110
 average
> 36.664


In your first case, what's the value of 'total' *before* all the
things you've typed in?

Can you say more why you expected to see the same result here as in
the next program?  They do look textually different, so I'd expect
them to likely have a different meaning, so I'm confused as to what
your expectations are.  Say more about why you expected them to be the
same, and maybe we can understand better.





> total=0
 total=total+10
 total=total+25
 total=total+25
 average=total/3
 average
> 20.0

Your second case makes sense.  10 + 25 + 25 is 60, and if we divide 60
by 3, the we'd expect the average to be twenty.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2015-03-03 Thread chelseysp

don't understand why these execute different things…




 total=total+10
>>> total=total+25
>>> total=total+25
>>> average=total/3
>>> total
110
>>> average
36.664




and 







total=0
>>> total=total+10
>>> total=total+25
>>> total=total+25
>>> average=total/3
>>> average
20.0






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


  1   2   3   4   5   6   7   >