Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Align columns
#1
Hi all,

Sorry for what is probably a really stupid question but, I started a data analytics course this week, having never done any coding before and unfortunately the tutor wasn't great for absolute beginners.

We have been set a lot of homework, most of which I have managed to workout but, I am stuck with just one thing.

The print I do at the end, how do I get it all to align in 3 perfect columns and how do I add titles at of the columns? For the former I have tried just about everything and I think I am making myself more and more confused.

Thanks for your help.

gm = 0
gm1 = 0
gm2 = 0
gm3 = 0
gm4 = 0
gm5 = 0
gm6 = 0
gm7 = 0
gm8 = 0
gm9 = 0

for x in data:
    if x in range(0,10):
        gm += 1
    elif x in range(10,20):
        gm1 += 1
    elif x in range(20,30):
        gm2 += 1
    elif x in range(30,40):
        gm3 += 1
    elif x in range(40,50):
        gm4 += 1
    elif x in range(50,60):
        gm5 += 1
    elif x in range(60,70):
        gm6 += 1
    elif x in range(70,80):
        gm7 += 1
    elif x in range(80,90):
        gm8 += 1
    elif x in range(90,100):
        gm9 += 1
            

grademark = [gm,gm1,gm2,gm3,gm4,gm5,gm6,gm7,gm8,gm9]
grades = ["0 - 10",
             "10 - 20",	 
             "20 - 30 ",
             "30 -40",	 
             "40-50",
             "50 - 60",
             "60 - 70",	 
             "70 - 80 ",
             "80 - 90",	 
             "90 - 100"]

for i in range(len(grades)):
    print("{:}{:6}{:6}".format(grades[i], grademark[i],'*' * grademark[i]))
Moderator Note: Closing python tag needs '/' preceeding 'python'
Reply


Messages In This Thread
Align columns - by bentley - Jan-12-2019, 09:55 PM
RE: Align columns - by Larz60+ - Jan-12-2019, 10:39 PM
RE: Align columns - by ichabod801 - Jan-12-2019, 11:08 PM
RE: Align columns - by bentley - Jan-12-2019, 11:18 PM
RE: Align columns - by Larz60+ - Jan-13-2019, 03:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Map plot does not align with quiver Gaben321 0 1,094 Jun-10-2022, 05:26 AM
Last Post: Gaben321

Forum Jump:

User Panel Messages

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