[Tutor] help please

2018-10-10 Thread Michael Schmitt
To whom it may concern:


I am trying to teach myself Python and ran into a problem. This is my code


# name of rivers and country

rivers = {'nile' : 'egypt', 'ohio' : 'US', 'rhine' : 'germany' }

# prints river name
for rivers in rivers.keys():
print (rivers)

#prints country
for rivers in rivers.values():
print (rivers)

# prints statement " The (river) is in the country of (country)
for rivers in rivers:
print ("The " + rivers.keys() + "is in the country of " + rivers.vaules())

I am getting the following error
 for rivers in rivers.values():
AttributeError: 'str' object has no attribute 'values'

Thanks for the help.

Sincerely,

Michael S. Schmitt


[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
Virus-free. 
www.avast.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help please

2018-10-10 Thread Peter Otten
Michael Schmitt wrote:

> To whom it may concern:
> 
> 
> I am trying to teach myself Python and ran into a problem. This is my code

> I am getting the following error
>  for rivers in rivers.values():
> AttributeError: 'str' object has no attribute 'values'

> # prints river name
> for rivers in rivers.keys():
> print (rivers)

Look closely at the loop above. What is the value of the "rivers" variable 
after the first iteration?

To resolve the problem simply use a different name as the loop variable.

Pro tip: When you loop over a dict you get the keys by default. So:

for river in rivers:
print(river)

> # prints statement " The (river) is in the country of (country)
> for rivers in rivers:
> print ("The " + rivers.keys() + "is in the country of " + 
rivers.vaules())
> 

Here's a logic (and a spelling) error: rivers.keys() comprises all rivers 
and rivers.values() all countries in the dict. You want to loop over 
rivers.items() which gives you (river, country) pairs.

Tip: print() automatically inserts spaces between its arguments. So:

for river, country in rivers.items():
print("River", river, "is in", country)

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


Re: [Tutor] Advanced python recommendations

2018-10-10 Thread Mark Lawrence

On 10/10/18 02:22, boB Stepp wrote:

On Tue, Oct 9, 2018 at 6:54 PM Mariam Haji  wrote:


Hi guys, I am on the last exercises of learn python the hard by Zed.A Shaw and 
I am looking for recommendations on what to follow next or what book to try 
next to advance my python skills to intermediate level.


If you are a fan of Zed Shaw's approach, I noticed while at Barnes &
Noble a while back that he has released a sequel to the book you
cited, but only for the Python 3 version.  You may be interested in
that.

But I imagine taking time to imagine, detail and write the code for
projects would help you the most, as the others have said.




After the disgraceful way that Zed Shaw wrote about Python 3 
https://learnpythonthehardway.org/book/nopython3.html I wouldn't touch 
his stuff with a 100 foot long disinfected barge pole.  Just a few 
months after this article he came out with the Python 3 book you 
reference above, presumably because he was losing cash.


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

Mark Lawrence

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


Re: [Tutor] help please

2018-10-10 Thread Abdur-Rahmaan Janhangeer
i think it should have been

for river in rivers instead of
for rivers in rivers

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ
Mauritius
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help please

2018-10-10 Thread Deepak Dixit
On Wed, Oct 10, 2018, 12:37 PM Michael Schmitt 
wrote:

> To whom it may concern:
>
>
> I am trying to teach myself Python and ran into a problem. This is my code
>
>
> # name of rivers and country
>
> rivers = {'nile' : 'egypt', 'ohio' : 'US', 'rhine' : 'germany' }
>
> # prints river name
> for rivers in rivers.keys():
> print (rivers)
>
> #prints country
> for rivers in rivers.values():
> print (rivers)
>
> # prints statement " The (river) is in the country of (country)
>

  Why are you using "for rivers in rivers".
  Replace this for loop with :-

  for river in rivers:
 print ("The " + river + "is in the country of " + rivers.get(river))

for rivers in rivers:
> print ("The " + rivers.keys() + "is in the country of " +
> rivers.vaules())
>
> I am getting the following error
>  for rivers in rivers.values():
> AttributeError: 'str' object has no attribute 'values'
>
> Thanks for the help.
>
> Sincerely,
>
> Michael S. Schmitt
>
>
> [
> https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif
> ]<
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>   Virus-free. www.avast.com<
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link
> >
> ___
> 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] help please

2018-10-10 Thread Mirage Web Studio
You are using the same variable name twice.
You may use "rivers" for the dict and "river" for values.
Also use descriptive names for variables. For eg if you correct the above
mistake, the next one will be this line

for rivers in rivers.values():
print (rivers)


and sorry for top positing.


On Wed 10 Oct, 2018, 12:38 Michael Schmitt, 
wrote:

> To whom it may concern:
>
>
> I am trying to teach myself Python and ran into a problem. This is my code
>
>
> # name of rivers and country
>
> rivers = {'nile' : 'egypt', 'ohio' : 'US', 'rhine' : 'germany' }
>
> # prints river name
> for rivers in rivers.keys():
> print (rivers)
>
> #prints country
> for rivers in rivers.values():
> print (rivers)
>
> # prints statement " The (river) is in the country of (country)
> for rivers in rivers:
> print ("The " + rivers.keys() + "is in the country of " +
> rivers.vaules())
>
> I am getting the following error
>  for rivers in rivers.values():
> AttributeError: 'str' object has no attribute 'values'
>
> Thanks for the help.
>
> Sincerely,
>
> Michael S. Schmitt
>
>
> [
> https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif
> ]<
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>   Virus-free. www.avast.com<
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link
> >
> ___
> 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] Advanced python recommendations

2018-10-10 Thread Mariam Haji
Thank you all for the above tips.
I actually did python 2 a friend sent it to me. And my current challenge
with the projects bit is how to pseudo-code and which approach to use as I
am not very familiar with the entire python syntax and how I can use it and
as well as python algorithms.

So like I get a problem to create a simple loop or remove duplicates from a
list and that just doesn't process in my head and I always end up having to
google, then build from there.

But thank you, I guess i just have to be patient it's been 3 months since I
started coding and development I am more of a front-end developer.

I guess I just need to learn how to break down the problems and know what
to use where.

On Wed, Oct 10, 2018 at 12:44 PM Mark Lawrence 
wrote:

> On 10/10/18 02:22, boB Stepp wrote:
> > On Tue, Oct 9, 2018 at 6:54 PM Mariam Haji 
> wrote:
> >>
> >> Hi guys, I am on the last exercises of learn python the hard by Zed.A
> Shaw and I am looking for recommendations on what to follow next or what
> book to try next to advance my python skills to intermediate level.
> >
> > If you are a fan of Zed Shaw's approach, I noticed while at Barnes &
> > Noble a while back that he has released a sequel to the book you
> > cited, but only for the Python 3 version.  You may be interested in
> > that.
> >
> > But I imagine taking time to imagine, detail and write the code for
> > projects would help you the most, as the others have said.
> >
> >
>
> After the disgraceful way that Zed Shaw wrote about Python 3
> https://learnpythonthehardway.org/book/nopython3.html I wouldn't touch
> his stuff with a 100 foot long disinfected barge pole.  Just a few
> months after this article he came out with the Python 3 book you
> reference above, presumably because he was losing cash.
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


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


Re: [Tutor] Advanced python recommendations

2018-10-10 Thread Abdur-Rahmaan Janhangeer
apart from already said, see popular python projects, and read the source
as you would read a book. you'll discover amazing tricks, it'll broaden
your horizon. hanging around those who achieved a good level will make you
level up.

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


Re: [Tutor] Advanced python recommendations

2018-10-10 Thread Alan Gauld via Tutor
On 10/10/18 10:53, Mariam Haji wrote:
>...my current challenge
> with the projects bit is how to pseudo-code and which approach to use as I
> am not very familiar with the entire python syntax and how I can use it 

And that's the whole point of doing projects. You need to
really be comfortable with the basics of breaking a problem
down into code sized chunks and debugging basic syntax
before you start thinking about mo9re advanced stuff.

Think of a regular task you could automate, or invent
a game, whatever takes your fancy. Then work on it and
as you get stuck send your code here and we will try
to help you fix it.

Remember keep it simple to start with. Even just copying
the files in a work folder to a backup folder, or a
little music or photo catalogue tool.

And start small, get the basics working before adding
extra features - test each feature as you add it, don't
wait till you have a mountain of code to debug.

-- 
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] Advanced python recommendations

2018-10-10 Thread Mats Wichmann
On 10/10/2018 10:46 AM, Alan Gauld via Tutor wrote:
> On 10/10/18 10:53, Mariam Haji wrote:
>> ...my current challenge
>> with the projects bit is how to pseudo-code and which approach to use as I
>> am not very familiar with the entire python syntax and how I can use it 
> 
> And that's the whole point of doing projects. You need to
> really be comfortable with the basics of breaking a problem
> down into code sized chunks and debugging basic syntax
> before you start thinking about mo9re advanced stuff.
> 
> Think of a regular task you could automate, or invent
> a game, whatever takes your fancy. Then work on it and
> as you get stuck send your code here and we will try
> to help you fix it.
> 
> Remember keep it simple to start with. Even just copying
> the files in a work folder to a backup folder, or a
> little music or photo catalogue tool.
> 
> And start small, get the basics working before adding
> extra features - test each feature as you add it, don't
> wait till you have a mountain of code to debug.
> 

This is actually the concept of test driven development (TDD), which I'm
not a huge proponent of personally, but kind of useful for this:

- write a test for some behavior you need, and get the test "working" so
that it fails because you don't have the code for the behavior yet
- code up the behavior until the test passes
- rinse, repeat

it really forces you not to write things in too complex a way up front!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Advanced python recommendations

2018-10-10 Thread boB Stepp
On Wed, Oct 10, 2018 at 12:09 PM Mats Wichmann  wrote:

> This is actually the concept of test driven development (TDD), which I'm
> not a huge proponent of personally, but kind of useful for this:

I'm curious:  What are the things you find less than satisfactory for TDD?

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


Re: [Tutor] Advanced python recommendations

2018-10-10 Thread Mats Wichmann
On 10/10/2018 01:20 PM, boB Stepp wrote:
> On Wed, Oct 10, 2018 at 12:09 PM Mats Wichmann  wrote:
> 
>> This is actually the concept of test driven development (TDD), which I'm
>> not a huge proponent of personally, but kind of useful for this:
> 
> I'm curious:  What are the things you find less than satisfactory for TDD?

Probably that I'm an old fogey who learned programming a different way
:)  And, it's off topic, so I'll just quickly say:

"TDD as religion" seems to me to lead to an absence of thinking about
overall system design, and system testing.  An excess focus on the unit,
because that's what you get when you build from unit tests on up,
doesn't necessarily get you a good System, and the vast majority of your
users will interact with your software at the system level

I'm fine with people using it as a general approach, just not as
unbreakable dogma - the same way I feel about most software development
methodology fads, actually.

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