## I need to Optimize this code.

This is the place for queries that don't fit in any of the other categories.

### I need to Optimize this code.

I have been given this code to optimize and I think you have to add an array and a loop, if you are able to help me could you explain what you have done please.

Code: Select all
`item1 = int(raw_input("Please enter the amount for item 1")) item2 = int(raw_input("Please enter the amount for item 2"))item3 = int(raw_input("Please enter the amount for item 3"))item4 = int(raw_input("Please enter the amount for item 4")) item5 = int(raw_input("Please enter the amount for item 5")) total = 0total = total + item1total = total + item2total = total + item3total = total + item4total = total + item5 print (str(total))`
Last edited by stranac on Sun Oct 06, 2013 12:45 pm, edited 1 time in total.
Reason: Locked
Tristian_Ruben

Posts: 1
Joined: Sun Oct 06, 2013 10:04 am

### Re: I need to Optimize this code.

You are expected to show an attempt you've made.
There is plenty of information on loops and lists(I doubt you want arrays) in the python tutorial, as well as in any book you might be learning from.
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1596
Joined: Thu Feb 07, 2013 3:42 pm

### Re: I need to Optimize this code.

What do you mean "optimize"? I would change this code to use a loop, because it's better convention, but when we usually talk about efficiency we mean time complexity (big-O) which can't really change here.
Join the #python-forum IRC channel on irc.freenode.net for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from

micseydel

Posts: 2253
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Who is online

Users browsing this forum: Google [Bot] and 3 guests