This is the place for queries that don't fit in any of the other categories.
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 = 0
total = total + item1
total = total + item2
total = total + item3
total = total + item4
total = total + item5
Last edited by stranac
on Sun Oct 06, 2013 12:45 pm, edited 1 time in total.
- Posts: 1
- Joined: Sun Oct 06, 2013 10:04 am
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.
- Posts: 1092
- Joined: Thu Feb 07, 2013 3:42 pm
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!
- Posts: 1113
- Joined: Tue Feb 12, 2013 2:18 am
- Location: Mountain View, CA
Return to General Coding Help
Who is online
Users browsing this forum: Google [Bot], Larz60+, Majestic-12 [Bot] and 4 guests