Two Dictionaries and a Sum!

2013-05-17 Thread Bradley Wright
Confusing subject for a confusing problem (to a novice like me of course!)
Thx for the help in advance folks

I have (2) dictionaries:

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

Here's my instructions:

consider this as an inventory and calculate the sum (thats 4*6 = 24 bananas!)

HERES MY CODE:

for key in prices:
print prices[key]*stock[key]

HERES THE OUTPUT:

48.0
45
24
0

ISSUE:
I need to find a way to add all of those together...any pointers?
-- 
http://mail.python.org/mailman/listinfo/python-list


Novice Issue

2013-04-17 Thread Bradley Wright
Good Day all, currently writing a script that ask the user for three things;
1.Name
2.Number
3.Description
I've gotten it to do this hurah!

print "Type \"q\" or \"quit\" to quit"
while raw_input != "quit" or "q":

print ""
name = str(raw_input("Name: "))
number = str(raw_input("Number: "))
description = str(raw_input("Description: "))

but here a few things, can anyone help me on figuring out how to at the users 
whim print out all of the names, numbers and descriptions. this is sort of an 
information logger.

additionally, minor issue with getting script to stop when q or quit is typed

any help would be greatly appreciated
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Novice Issue

2013-04-18 Thread Bradley Wright
On Thursday, April 18, 2013 12:06:59 AM UTC-4, Bradley Wright wrote:
> Good Day all, currently writing a script that ask the user for three things;
> 
> 1.Name
> 
> 2.Number
> 
> 3.Description
> 
> I've gotten it to do this hurah!
> 
> 
> 
> print "Type \"q\" or \"quit\" to quit"
> 
> while raw_input != "quit" or "q":
> 
> 
> 
> print ""
> 
> name = str(raw_input("Name: "))
> 
> number = str(raw_input("Number: "))
> 
> description = str(raw_input("Description: "))
> 
> 
> 
> but here a few things, can anyone help me on figuring out how to at the users 
> whim print out all of the names, numbers and descriptions. this is sort of an 
> information logger.
> 
> 
> 
> additionally, minor issue with getting script to stop when q or quit is typed
> 
> 
> 
> any help would be greatly appreciated

Joining this group has been the smartest decision since birth 

Firstly, thanks Chris - str() [REMOVED]
and yes i would like to retain them until the end of the loop simply for 
printing or viewing purposes. [I'll DO MORE RESEARCH ON LISTS] 

Secondly, thanks Wolfgang
while raw_input not in ("quit", "q") - genius, i get your point clearly

Thirdly, thanks mark
went through the link you provided, insightful

Cheers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Novice Issue

2013-04-18 Thread Bradley Wright
On Thursday, April 18, 2013 12:06:59 AM UTC-4, Bradley Wright wrote:
> Good Day all, currently writing a script that ask the user for three things;
> 
> 1.Name
> 
> 2.Number
> 
> 3.Description
> 
> I've gotten it to do this hurah!
> 
> 
> 
> print "Type \"q\" or \"quit\" to quit"
> 
> while raw_input != "quit" or "q":
> 
> 
> 
> print ""
> 
> name = str(raw_input("Name: "))
> 
> number = str(raw_input("Number: "))
> 
> description = str(raw_input("Description: "))
> 
> 
> 
> but here a few things, can anyone help me on figuring out how to at the users 
> whim print out all of the names, numbers and descriptions. this is sort of an 
> information logger.
> 
> 
> 
> additionally, minor issue with getting script to stop when q or quit is typed
> 
> 
> 
> any help would be greatly appreciated

Thanks Dave quite helpful as well,
now i have a clear road to go on, with regards the lists portion of my script
-- 
http://mail.python.org/mailman/listinfo/python-list


(Learner-here) Lists + Functions = headache

2013-05-05 Thread Bradley Wright
Hey guys and gals doing this tutorial(codecademy) and needed a bit help from 
the experienced.

I'm writing a function that takes a list(one they supply during runtime)
here's what my function is supposed to do

1. for each instance of the string "fizz" make a count
2. Finally return that count

here's my code:

def fizz_cout(x):
count = 0
for item in x:
while item == "fizz":
count += 1
return count

Please remember that i am a eager beginner, where am i going wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (Learner-here) Lists + Functions = headache

2013-05-05 Thread Bradley Wright
On Sunday, May 5, 2013 9:21:33 PM UTC-4, alex23 wrote:
> On May 6, 10:59 am, Bradley Wright 
> 
> wrote:
> 
> > def fizz_cout(x):
> 
> >     count = 0
> 
> >     for item in x:
> 
> >         while item == "fizz":
> 
> >             count += 1
> 
> >             return count
> 
> >
> 
> > Please remember that i am a eager beginner, where am i going wrong?
> 
> 
> 
> There are several problems with your code:
> 
> 
> 
> >     for item in x:
> 
> >         while item == "fizz":
> 
> >             count += 1
> 
> 
> 
> The `for` takes an item out of the list `x`. If that item is the
> 
> string 'fizz', it increments count. As it's a `while` loop, it will
> 
> continue to increment for as long as `item` is 'fizz'. Since the while
> 
> loop doesn't look up another list item, it will remain as 'fizz' until
> 
> the end of time. Well, it would except for your second bug:
> 
> 
> 
> >         while item == "fizz":
> 
> >             count += 1
> 
> >             return count
> 
> 
> 
> The very first time it encounters a list item that is 'fizz', it adds
> 
> one to `count`, then exits the function passing back `count`.
> 
> 
> 
> You want to move the return to _outside_ the for loop, and you want to
> 
> change your `while` condition to an `if` instead.

Thank you Alex - much appreciated, about to implement right now!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (Learner-here) Lists + Functions = headache

2013-05-05 Thread Bradley Wright
On Sunday, May 5, 2013 9:24:44 PM UTC-4, Bradley Wright wrote:
> On Sunday, May 5, 2013 9:21:33 PM UTC-4, alex23 wrote:
> 
> > On May 6, 10:59 am, Bradley Wright 
> 
> > 
> 
> > wrote:
> 
> > 
> 
> > > def fizz_cout(x):
> 
> > 
> 
> > >     count = 0
> 
> > 
> 
> > >     for item in x:
> 
> > 
> 
> > >         while item == "fizz":
> 
> > 
> 
> > >             count += 1
> 
> > 
> 
> > >             return count
> 
> > 
> 
> > >
> 
> > 
> 
> > > Please remember that i am a eager beginner, where am i going wrong?
> 
> > 
> 
> > 
> 
> > 
> 
> > There are several problems with your code:
> 
> > 
> 
> > 
> 
> > 
> 
> > >     for item in x:
> 
> > 
> 
> > >         while item == "fizz":
> 
> > 
> 
> > >             count += 1
> 
> > 
> 
> > 
> 
> > 
> 
> > The `for` takes an item out of the list `x`. If that item is the
> 
> > 
> 
> > string 'fizz', it increments count. As it's a `while` loop, it will
> 
> > 
> 
> > continue to increment for as long as `item` is 'fizz'. Since the while
> 
> > 
> 
> > loop doesn't look up another list item, it will remain as 'fizz' until
> 
> > 
> 
> > the end of time. Well, it would except for your second bug:
> 
> > 
> 
> > 
> 
> > 
> 
> > >         while item == "fizz":
> 
> > 
> 
> > >             count += 1
> 
> > 
> 
> > >             return count
> 
> > 
> 
> > 
> 
> > 
> 
> > The very first time it encounters a list item that is 'fizz', it adds
> 
> > 
> 
> > one to `count`, then exits the function passing back `count`.
> 
> > 
> 
> > 
> 
> > 
> 
> > You want to move the return to _outside_ the for loop, and you want to
> 
> > 
> 
> > change your `while` condition to an `if` instead.
> 
> 
> 
> Thank you Alex - much appreciated, about to implement right now!

Aha! lessons learned - got it!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a way to collect twitts with python?

2009-04-04 Thread Bradley Wright
Just to pimp my own wares:

http://github.com/bradleywright/yatcip/tree/master

A Python Twitter client.
--
http://mail.python.org/mailman/listinfo/python-list