Python Forum
String index out of range - help please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String index out of range - help please
#1
I'm new to programming btw.
I'm trying to write a program that will take a tuple of a list of toys, a tuple of the base prices for those toys, and calculate a 40% mark up and the final price (mark up + base) to get the retail price and then print the toys in one column, the base costs in one column, the mark up in one column, and the final price in one column. Here is what it should look like
[Image: 5pH2QMo.png]

Here is my program, which currently gets a string index out of range error and prints it incorrectly. Please help.

#Variable List
# toys - the tuple for the list of toys
# costs - the tuple for the costs of each toy
# mark - the 40 percent mark up
# retail - the base cost plus mark up
# count - the counter/sentry


print ("Welcome to the Mark Up program")
#step 1 - this will set up the toys tuple and the base cost of each 
toys = ("Teddy Bear","Toy Train","Hoola Hoop","Betsy Wetsy","Pogo stick")
costs = (12.50,58.75,10.00,15.00,11.00)

#step 2 -  set up the for loop to calculate mark up on each toy
print ("Item","\t\t","Cost","\t\t","Mark Up","\t\t","Retail")

#step 3 - this will print and format the output

for num in range(len(costs)):
    mark = num * .4
    retail = mark + num
    costs = str(costs)
    mark = str(mark)
    retail = str(retail)
    print (toys[num],"\t",costs[num],"\t",mark[num],"\t",retail[num])
    
Reply


Messages In This Thread
String index out of range - help please - by DudleyDiccle - Mar-26-2020, 07:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Down I hate "List index out of range" Melen 20 3,305 May-14-2023, 06:43 AM
Last Post: deanhystad
Exclamation IndexError: Replacement index 2 out of range for positional args tuple - help? MrKnd94 2 6,316 Oct-14-2022, 09:57 PM
Last Post: MrKnd94
  IndexError: list index out of range dolac 4 1,900 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  I'm getting a String index out of range error debian77 7 2,332 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,436 May-03-2022, 01:39 PM
Last Post: Anldra12
  matplotlib x axis range goes over the set range Pedroski55 5 3,176 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  IndexError: list index out of range rf_kartal 6 2,834 Sep-07-2021, 02:36 PM
Last Post: Larz60+
  Python Error List Index Out of Range abhi1vaishnav 3 2,301 Sep-03-2021, 08:40 PM
Last Post: abhi1vaishnav
  IndexError: list index out of range Laplace12 1 2,219 Jun-22-2021, 10:47 AM
Last Post: Yoriz
  IndexError: list index out of range brunolelli 11 6,491 Mar-25-2021, 11:36 PM
Last Post: brunolelli

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020