Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting Help!
#2
So the most letters from a month is 9, so I just put extra spaces in between the month and stars based on how many letters were in that month. For example in June, there are an extra 5 spaces. You can take a look at the code below.
#Variable List
# months - the tuple for months
# sales - the corresponding sales for each month
 
print ("Welcome to the Artic Dog program")
#step 1 - this will create a tuple for the months and sales
months = ("January","February","March","April","May","June","July","August","September","October","November","December")
sales = (28,30,24,10,12,10,5,3,4,10,21,25)
 
# step 3 - this will print and format the months and bar graph
total = 0
count = 0
for item in months:
    print (item," "*(9-len(item)), "{:<30}".format(sales[count]*"*"))
    count = count + 1
for num in sales:
    total = num + total
print ("Total Sold for 20XX","{:<30}".format(total))
Reply


Messages In This Thread
Formatting Help! - by DudleyDiccle - Mar-26-2020, 05:03 PM
RE: Formatting Help! - by SheeppOSU - Mar-26-2020, 05:26 PM
RE: Formatting Help! - by DudleyDiccle - Mar-26-2020, 05:32 PM

Forum Jump:

User Panel Messages

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