[Tutor] Having Unusual results

Alan Gauld alan.gauld at btinternet.com
Sat May 2 09:52:51 CEST 2015


On 02/05/15 05:12, Jag Sherrington wrote:
> Hi Can anyone tell me where I am going wrong the end result doesn't add up?

I assume you are posting in HTML, your code is very hard to read with 
missing newlines. Please check your settings and post in plain text.

I'm not sure what you mean by "doesn't add up"?
What were you expecting to be different?
Is it the 2.0 and 2.5 in the last two results?

> people = int(input('Enter how many people '))numdogs = int(input('Enter how many dogs '))
> hotdogs = 10buns = 8dogsleft = 0bunsleft = 0
> # total number of hot dogs neededdogs_needed = (numdogs * people)
> # how many packages of hot dogspackdogs = (dogs_needed / hotdogs)
> # how many packs of buns neededpackbuns = (dogs_needed / buns)
> # how many hot dogs leftdogsleft = (packdogs * 10, - dogs_needed)

One thing that is odd. Why did you separate this calculation
with the comma? Were you intending completing it later on?

> # how many buns leftbunsleft = (packbuns * 8, - dogs_needed)

same here

> print('Here are the details:')
> print('Total hot dogs needed: ', dogs_needed)
> print('Packs of hot dogs ', packdogs)
> print('Packs of buns ', packbuns)
> print('Dogs left: ', dogsleft)
> print('Buns left: ', bunsleft)

> THIS IS THE RESULT
Enter how many people 10
Enter how many dogs 2
Here are the details:
Total hot dogs needed:  20
Packs of hot dogs  2.0
Packs of buns  2.5
Dogs left:  (2.0, -20)
Buns left:  (2.5, -20)

Assuming its the 2.0 and 2.5 that you are querying, I confess I'm 
confused too. I don't get that when I run your code (after fixing
the newlines):

Enter how many people 10
Enter how many dogs 2
Here are the details:
Total hot dogs needed:  20
Packs of hot dogs  2.0
Packs of buns  2.5
Dogs left:  (20.0, -20)
Buns left:  (20.0, -20)

Which is exactly what I'd expect.

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




More information about the Tutor mailing list