Re: [Tutor] Tutor Digest, Vol 176, Issue 13

2018-10-12 Thread Adam Eyring
Also, try (works for me in Python3)
rivers = {'nile' : 'egypt', 'ohio' : 'US', 'rhine' : 'germany' }

for key, value in rivers.items():
print (key)

for key, value in rivers.items():
print (value)

for key, value in rivers.items():
print ("The " + key + " is in the country of " + value)


On Thu, Oct 11, 2018 at 12:41 PM Rajnish Sinha <
rajnish.si...@infoprolearning.com> wrote:

> Try
> for river in rivers:
> print ("The " + river + " is in the country of " + rivers[river])
>
> On Wed, Oct 10, 2018 at 9:30 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: help please (Abdur-Rahmaan Janhangeer)
> >2. Re: Advanced python recommendations (Abdur-Rahmaan Janhangeer)
> >3. Re: help please (Mirage Web Studio)
> >4. Re: help please (Deepak Dixit)
> >5. Re: Advanced python recommendations (Mariam Haji)
> >
> >
> >
> > -- Forwarded message --
> > From: Abdur-Rahmaan Janhangeer 
> > To: Michael Schmitt 
> > Cc: tutor 
> > Bcc:
> > Date: Wed, 10 Oct 2018 11:53:41 +0400
> > Subject: Re: [Tutor] help please
> > 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
> >
> >
> >
> >
> > -- Forwarded message --
> > From: Abdur-Rahmaan Janhangeer 
> > To: Mariam Haji 
> > Cc: Tutor@python.org
> > Bcc:
> > Date: Wed, 10 Oct 2018 14:26:24 +0400
> > Subject: Re: [Tutor] Advanced python recommendations
> > 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
> >
> >
> >
> >
> > -- Forwarded message --
> > From: Mirage Web Studio 
> > To: Michael Schmitt , Python Tutor Mailing
> > List 
> > Cc:
> > Bcc:
> > Date: Wed, 10 Oct 2018 13:45:40 +0530
> > Subject: Re: [Tutor] help please
> > 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
> > >
> >
> >
> >
> >
> > -- Forwarded message --
> > From: Deepak Dixit 
> > To: Michael Schmitt 
> > Cc: tutor@python.org
> > Bcc:
> > Date: Wed, 10 Oct 2018 12:43:46 +0530
> > Subject: Re: [Tutor] help please
> > On Wed, Oct 10, 2018, 12:37 PM Michael Schmitt <
> mikeschmitt...@outlook.com
> > >
> > 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', 'oh

Re: [Tutor] Help please

2018-10-12 Thread Adam Eyring
The program works as is in Python3. For Python2, change input to raw_input
and see if that makes it work (I know it worked for me when I had Python2).
Also, it looks better to use " + " instead of a comma:
print("Combining these foods will you," + new_food)

Also, colons and spaces are good practices when using input boxes, such as
food_1=raw_input("Sushi: ")


On Thu, Oct 11, 2018 at 1:23 PM Carlton Banks  wrote:

> https://www.w3schools.com/python/ref_func_input.asp
>
> tor. 11. okt. 2018 18.51 skrev Carlton Banks :
>
> > What are you trying to do?
> >
> > tor. 11. okt. 2018 18.33 skrev Holly Jo :
> >
> >>
> >> I have no clue what I’m doing wrong, I’m a new student
> >>
> >> food_1=input("Sushi")
> >> food_2=input("Quesdilla")
> >> new_food=food_1+food_2
> >> print("Combining these foods will you,",new_food)
> >> input("Press enter to continue")
> >>
> >>
> >> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python

2018-10-12 Thread Tyler Travis via Tutor
I fully understand the concept of what I am trying to do and I know that you 
can type out the algorithms to find mean, median, and mode but I used a 
shortcut by import the statistics function. Which yields the same results and 
the program passes with a 100% in the grading software However, it does not 
print the expected output, but rather some random sequence of characters and 
numbers. I do not understand why. Do you know why?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python

2018-10-12 Thread Mark Lawrence

On 12/10/18 02:41, Tyler Travis via Tutor wrote:

I fully understand the concept of what I am trying to do and I know that you 
can type out the algorithms to find mean, median, and mode but I used a 
shortcut by import the statistics function. Which yields the same results and 
the program passes with a 100% in the grading software However, it does not 
print the expected output, but rather some random sequence of characters and 
numbers. I do not understand why. Do you know why?



No, as I do not see any code, data, Python version or OS.

--
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-12 Thread Mark Lawrence

On 12/10/18 04:31, Adam Eyring wrote:

The program works as is in Python3. For Python2, change input to raw_input
and see if that makes it work (I know it worked for me when I had Python2).
Also, it looks better to use " + " instead of a comma:
print("Combining these foods will you," + new_food)

Also, colons and spaces are good practices when using input boxes, such as
food_1=raw_input("Sushi: ")



Please don't top post as it makes reading long threads really irritating.

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

Mark Lawrence

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


Re: [Tutor] Python

2018-10-12 Thread Steven D'Aprano
On Thu, Oct 11, 2018 at 08:41:08PM -0500, Tyler Travis via Tutor wrote:

> I fully understand the concept of what I am trying to do 

I'm very glad that at least one of us understands what you are trying to 
do, but I have no clue what it is.


> and I know 
> that you can type out the algorithms to find mean, median, and mode 
> but I used a shortcut by import the statistics function. Which yields 
> the same results 

The same results as what?


> and the program passes with a 100% in the grading software 

Great!


> However, it does not print the expected output, but rather 
> some random sequence of characters and numbers. I do not understand 
> why. Do you know why?

Your computer is cursed? Your cat walked over the keyboard?

I don't understand how your two statements can be reconciled. You say 
that the program pass the grading software. Surely that means it must 
print the expected output. (How else will the grading software know it 
gives the correct results?)

But then you say it prints gibberish. So I imagine you are doing this:

print(mean([1, 2, 8, 9])  # expected output is "5"

# output actually printed is "dz!gwd{7p3^)n3d%hw8"
# and the grading software says "Correct, full marks!"

which makes no sense to me.

By the way, I'm the author of the statistics module, so I'm very glad to 
hear that you are using it, but if the point of the exercise is to write 
your own (simple?) versions of mean, median and mode, isn't it cheating 
to use the pre-written ones?



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


Re: [Tutor] Help please

2018-10-12 Thread Alan Gauld via Tutor
On 12/10/18 04:31, Adam Eyring wrote:

> Also, it looks better to use " + " instead of a comma:
> print("Combining these foods will you," + new_food)

It may "look better" but be aware that they don't do
the same thing and the plus sign is a lot less efficient
computationally since it creates a new string for
each addition.

For a simple case like this it won't matter but if
you had a lot of short strings being added together
in a loop it could slow things down quite a bit.

The other problem with the plus sign is that it
requires all arguments to be strings whereas the
comma separated list gets automatically converted
to a string by Python (by calling str(x) ) so is
in general more reliable.

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


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


Re: [Tutor] Python

2018-10-12 Thread Alan Gauld via Tutor
On 12/10/18 02:41, Tyler Travis via Tutor wrote:
> I used a shortcut by import the statistics function. 
...
> it does not print the expected output, 

Did you by any chance include your code as an attachment?
If so this mail server will strip it out as a security risk.
Please post any code in the body of your email
(using plain text) please.

If you didn't send your code at all then please do so
as we are not mind readers! :-)

-- 
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