#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Basic Python List Excercise


    Hello everybody! How do I make this graph print vertically rather than horizontally? Please try to use the same concept(loops, lists) I used in my code so I understand the changes.
    Here is the code:
    Code:
    SIGN='x'
    
    test_list=[500000,5000000,7000000]
    test_calc_list=[]
    test_sum=sum(test_list)
    
    test_string_list=['Test1','Test2','Test3']
    signs_list=[]
    
    for x in test_list:
        test_calc=round((x/float(test_sum)*10))
        test_calc_list.append(test_calc)
    
    for y in test_calc_list:
        y=int(y)
        signs=y*SIGN
        signs_list.append(signs)
    
    for z in range(len(test_string_list)):
        print "%8s: %-6s %7i"% (test_string_list[z],signs_list[z],test_list[z])
    This is the output I get:
    Code:
       Test1:           500000
       Test2: xxxx     5000000
       Test3: xxxxxx   7000000
    This is the output I want:
    Code:
                          
                          x
               x          x
               x          x
               x          x
               x          x
    Test1      Test2      Test3        
    500000     5000000    7000000
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    Partial solution:
    Code:
    SIGN='x'
    
    test_list=[500000,5000000,7000000]
    test_calc_list=[]
    test_sum=sum(test_list)
    
    test_string_list=['Test1','Test2','Test3']
    signs_list=[]
    
    for x in test_list:
        test_calc=round((x/float(test_sum)*10))
        test_calc_list.append(test_calc)
    
    for y in test_calc_list:
        y=int(y)
        signs=y*SIGN
        signs_list.append(signs)
    
    A = []
    for z in range(len(test_string_list)):
        A.append("%8s: %-6s %7i"% (test_string_list[z],signs_list[z],test_list[z]))
    
    import itertools
    for L in itertools.izip_longest(*A,fillvalue=' '):
        print(' '.join(L))
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo