Mar-26-2020, 05:03 PM
Hi, I am trying to format the following code so that the stars are all aligned in a column, starting at the same spot, and the same with the months. The months are already aligned by default, but I can't get the stars to be aligned. I also need to align the total at the bottom. It should look like the following.
Example of Output:
Month Sales
January ****************************
February ******************************
March ************************
April **********
May ************
June **********
July *****
August ***
September ****
October **********
November *********************
December *************************
Total Sold for 20XX 182
Here is the code:
Example of Output:
Month Sales
January ****************************
February ******************************
March ************************
April **********
May ************
June **********
July *****
August ***
September ****
October **********
November *********************
December *************************
Total Sold for 20XX 182
Here is the code:
#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,"{:<30}".format(sales[count]*"*")) count = count + 1 for num in sales: total = num + total print ("Total Sold for 20XX","{:<30}".format(total))