Re: Why assert is not a function?

2021-03-04 Thread Grant Edwards
On 2021-03-03, Chris Angelico  wrote:
> On Thu, Mar 4, 2021 at 1:40 AM Grant Edwards  
> wrote:
>
>> I thought the entire point of asser being a keyword was so that if you
>> disable asserts then they go away completely: the arguments aren't
>> even evaluated.
>
> It depends on what the point of "removing the assertions" is, but
> yes, that will indeed still evaluate the arguments. IMO the cost of
> running assertions isn't that high compared to the value of keeping
> them (which is why I never run -O), and the performance argument is
> a weak one compared to the much stronger value of having the actual
> failing expression available in the exception report.

Good point. I had forgotten about having the expression available in
the exception output. That's definitly valuable.


-- 
https://mail.python.org/mailman/listinfo/python-list


Problem with printing statement when condition is false

2021-03-04 Thread Quentin Bock
Okay so, this is my biggest project, I'm not advanced in Python in any
way so don't expect it to be perfect. I made a trivia game and for the most
part, it works but I can't get it to print "Incorrect" and then what the
answer was for all but one of my questions and I don't know why. I use
PyCharm as my IDE for his just as a heads up. I won't paste the code into
this because it's 164 lines so I will attach a file copy, please don't send
back the edited file only write them out and where I need to fix them,
thank you!
Stay Safe Everyone! :)


Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with printing statement when condition is false

2021-03-04 Thread Terry Reedy

On 3/4/2021 12:10 PM, Quentin Bock wrote:


I won't paste the code into
this because it's 164 lines so I will attach a file copy,


The alternative to posting too much is to reduce your code to the 
minimum needed to exhibit the behavior you want to change.  Doing so may 
reveal to you the solution.  It will certainly make it easier for anyone 
else to help you and will make any answer more useful to other readers.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


program python

2021-03-04 Thread alberto
Hi I'm tring to write a program with python to evaluate data of csv data
In particular I would extract this information 

View data on the presence of men and women in Affori over time.

* Carry out an analysis relating to the last available year. Of the 10 most 
populous neighborhoods show:
* the proportion of births out of the total
* the proportion of 80+ to the total
* The ratio of minors / number of kindergartens

this is the file
https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing

How could fix it?

regards 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: program python

2021-03-04 Thread Igor Korot
Hi,

On Thu, Mar 4, 2021 at 2:42 PM alberto  wrote:
>
> Hi I'm tring to write a program with python to evaluate data of csv data
> In particular I would extract this information
>
> View data on the presence of men and women in Affori over time.
>
> * Carry out an analysis relating to the last available year. Of the 10 most 
> populous neighborhoods show:
> * the proportion of births out of the total
> * the proportion of 80+ to the total
> * The ratio of minors / number of kindergartens
>
> this is the file
> https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing
>
> How could fix it?

What seems to be the problem?

Thank you.

>
> regards
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: program python

2021-03-04 Thread dn via Python-list
Hi, and welcome to the list.

On 05/03/2021 09.36, alberto wrote:
> Hi I'm tring to write a program with python to evaluate data of csv data
> In particular I would extract this information 
> 
> View data on the presence of men and women in Affori over time.
> 
> * Carry out an analysis relating to the last available year. Of the 10 most 
> populous neighborhoods show:
> * the proportion of births out of the total
> * the proportion of 80+ to the total
> * The ratio of minors / number of kindergartens
> 
> this is the file
> https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing
> 
> How could fix it?


NB For security reasons, many will not follow this link/see the data-file!

There are several libraries which can be import-ed into Python, which
enable access to .csv-formatted files. The PSL (Python Standard Library)
offers "csv — CSV File Reading and Writing"
(https://docs.python.org/3/library/csv.html).

Start by writing the Python code to open the .csv file, and close it
again (as you would at the end of the program). Leave plenty of
blank/empty lines between the two, and use that space to continue with
the next steps...

There are three objectives.

To start, assume that the file is open in front of you. How will you
solve the first problem? Can you describe this in English (and/or your
preferred language)?

Write this as a Python comment. Next, can you translate the
spoken-language into Python?

Thereafter tackle problems two and three.


We don't know your level of Python skill. So, let us know how you
get-on, and come back with sample code, if you strike a problem at any step.
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: program python

2021-03-04 Thread Paul Bryan
I don't see a Python program in that link.

Are you asking how to extract data from a CSV?
A good start will be to look into the csv.reader function and
csv.DictReader class.

Paul

On Thu, 2021-03-04 at 12:36 -0800, alberto wrote:
> Hi I'm tring to write a program with python to evaluate data of csv
> data
> In particular I would extract this information 
> 
> View data on the presence of men and women in Affori over time.
> 
> * Carry out an analysis relating to the last available year. Of the
> 10 most populous neighborhoods show:
> * the proportion of births out of the total
> * the proportion of 80+ to the total
> * The ratio of minors / number of kindergartens
> 
> this is the file
> https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing
> 
> How could fix it?
> 
> regards 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with printing statement when condition is false

2021-03-04 Thread Terry Reedy

On 3/4/2021 3:15 PM, Terry Reedy wrote:

On 3/4/2021 12:10 PM, Quentin Bock wrote:


I won't paste the code into
this because it's 164 lines so I will attach a file copy,


The alternative to posting too much is to reduce your code to the 
minimum needed to exhibit the behavior you want to change.  Doing so may 
reveal to you the solution.  It will certainly make it easier for anyone 
else to help you and will make any answer more useful to other readers.


Quentin privately sent me 12 lines (which should have been posted here 
instead), which can be reduced to the following 4 that exhibit his bug.


if a == b:
print('correct')
if a != b:
print('incorrect')

The bug is a != b will never be true when a == b and will not be tested 
when a != b.  The fix is to use else.


if a == b:
print('correct')
else:
print('incorrect')

This should not be reduced to a conditional expression since different 
code follows the print statements in the actual example.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: program python

2021-03-04 Thread alberto
Il giorno giovedì 4 marzo 2021 alle 22:04:57 UTC+1 Paul Bryan ha scritto:
> I don't see a Python program in that link. 
> 
> Are you asking how to extract data from a CSV? 
> A good start will be to look into the csv.reader function and 
> csv.DictReader class. 
> 
> Paul
> On Thu, 2021-03-04 at 12:36 -0800, alberto wrote: 
> > Hi I'm tring to write a program with python to evaluate data of csv 
> > data 
> > In particular I would extract this information 
> > 
> > View data on the presence of men and women in Affori over time. 
> > 
> > * Carry out an analysis relating to the last available year. Of the 
> > 10 most populous neighborhoods show: 
> > * the proportion of births out of the total 
> > * the proportion of 80+ to the total 
> > * The ratio of minors / number of kindergartens 
> > 
> > this is the file 
> > https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing
> >  
> > 
> > How could fix it? 
> > 
> > regards

Hi, 
with this code
import pandas as pd
df = pd.read_csv('data.csv',usecols=['Uomini','Donne'])

print(df)
I extract two columns, but I would see 'Affori over time'

regards
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: program python

2021-03-04 Thread Igor Korot
Hi,

On Thu, Mar 4, 2021 at 4:42 PM alberto  wrote:
>
> Il giorno giovedì 4 marzo 2021 alle 22:04:57 UTC+1 Paul Bryan ha scritto:
> > I don't see a Python program in that link.
> >
> > Are you asking how to extract data from a CSV?
> > A good start will be to look into the csv.reader function and
> > csv.DictReader class.
> >
> > Paul
> > On Thu, 2021-03-04 at 12:36 -0800, alberto wrote:
> > > Hi I'm tring to write a program with python to evaluate data of csv
> > > data
> > > In particular I would extract this information
> > >
> > > View data on the presence of men and women in Affori over time.
> > >
> > > * Carry out an analysis relating to the last available year. Of the
> > > 10 most populous neighborhoods show:
> > > * the proportion of births out of the total
> > > * the proportion of 80+ to the total
> > > * The ratio of minors / number of kindergartens
> > >
> > > this is the file
> > > https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing
> > >
> > > How could fix it?
> > >
> > > regards
>
> Hi,
> with this code
> import pandas as pd
> df = pd.read_csv('data.csv',usecols=['Uomini','Donne'])
>
> print(df)
> I extract two columns, but I would see 'Affori over time'

And if you add this column to the list - what happens?

Thank you.

>
> regards
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list