Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:18:07+00:00 2026-06-16T05:18:07+00:00

i want to create a list or a dictionary not sure which niether have

  • 0

i want to create a list or a dictionary not sure which niether have worked so far
i need to convert text (user input) into numeric value and add them together
there are 4 possible answers
this is how i want it to work

each box contains fruit and are sold for differant prices

apple=25,oranges=35,pears=10,bananas=50,pineapple=40
totalprice=0
count=5
list = [box1,box2,box3,box4,box5,]
while count >0:
fruit=raw_input("what fruit is in ")(0)
count -=1
if fruit ==apples:
return "price 25"
totalprice=+25

i want this to run five times gathering the total price along the way

is there a away that whatever fruit they put in the corresponding value will be added to total price.
sorry if not explained very well new to programming

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:18:08+00:00Added an answer on June 16, 2026 at 5:18 am

    Firstly, it would make sense to use a dict to store fruit name – > price.

    fruits = {
        'apples': 25,
        'oranges': 35,
        'pears': 10,
        'bananas': 50,
        'pineapples': 40
    }
    

    Then we create an empty list, and loop over the numbers from 1 to 5 (note that 6 isn’t included in the range)…

    inputs = []
    for i in range(1, 6):
        inputs.append(raw_input('Enter fruit for box {}: '.format(i)))
    

    We then use sum that takes the inputs, and tries to look up the value in fruits…

    print sum(fruits[name] for name in inputs)
    

    Sample run:

    Enter fruit for box 1: bananas
    Enter fruit for box 2: bananas
    Enter fruit for box 3: bananas
    Enter fruit for box 4: pears
    Enter fruit for box 5: apples
    185
    

    Other things you could do are validate a fruit exists before appending it to inputs – but this should be enough for you to work with for the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create module which update list of usb devices automatically (not only mass
I`v come across a need where I want to create multiple list items from
I want to create a generic class which helps me to compare two dictionary
I need to write a script which merges a list with a dictionary to
I have created dictionary object Dictionary<string, List<string>> dictionary = new Dictionary<string,List<string>>(); I want to
I am new in ubuntu 12.04 LTS . I want to create list file
I want to create a list within a list item on jQuery mobile here's
I want to create a list of category terms (contained within a block), with
I want to create a list of GridBagPanel.Constraints . I read it in the
in my python code i want to create a list of lists...in a loop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.