0

Hi I got the following problem, I'm trying to build a program that reads a txt file that contains lines with name of fruits and their respective base prices as the following example:

apple $ 2.00

pearl $ 4.00

guava $ 2.50

and so it goes on.

Yesterday I had some help with people here and I've learned how to make python recognize their prices as a number instead of string, and i was able to multiply their values by one number that was asked to the user. Now I want to make this in a such way that I'm able to take each one of those prices and multiply them for different numbers (one different number for each price) that will be asked for the user to choose.

So far, with the help that I got yesterday I've done this:

print "this program will calculate the total price of the fruits"
y = input('insert a value = ')
with open('fruits.txt') as f:
for line in f:
    name, price = line.rstrip().split('$')
    price = float(price)
    cost = price * (0.76+y)
    tcost = cost + price
    print name, tcost

Any ideas how to do this?

3
  • Since you say you're new here I would like to suggest that you learn how to "accept" answers. On your previous question you said aix helped you a lot. On StackOverflow, when someone helps you, it is proper etiquette to click on the check box below the answer that best answers your question. This gives reputation to the answer, and to yourself. It also lets others know that the question was answered to your satisfaction. Commented Dec 15, 2011 at 17:13
  • do you need to ask a different value for every line of only for different fruits? Commented Dec 15, 2011 at 17:46
  • if this is homework you should tag it as such Commented Dec 17, 2011 at 10:32

1 Answer 1

1
mult_by = int(raw_input('gimme a number for something: '))

try and familiarize yourself with the basic built in functions, should be helpful.

http://docs.python.org/library/functions.html

Sign up to request clarification or add additional context in comments.

1 Comment

but this will make the program to multiply every line with the same number wont it? I want to multiply each line for different numbers...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.