[Tutor] python draw christman tree using loops

jarod_v6 at libero.it jarod_v6 at libero.it
Sun Oct 19 13:32:27 CEST 2014


Dear All,
or improve my understanding o python I would like to learn how to draw simple
figures using loops.
I start from this code in java:
import java.util.Scanner;

public class Eserc2_8 {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        // Altezza del triangolo
        int altezza = s.nextInt();
       
        for (int riga = 1; riga <= altezza; riga++) {
            int i = 0;
            while (i<altezza-riga) {
                System.out.print(" ");
                i += 1;
            }
            i = 0;
            while (i< (riga*2)-1) {
                System.out.print("*");
                i += 1;
            }
            System.out.println("");
        }
    }
}

and I want to transfer to python loops:

for i in range(10):
    #space
    for t in range(6-i):
        print ""
        for item in range(i+1):
            print "."


But I ha not succed. So someone could you please explain how can work'
thanks  a lot
bw





More information about the Tutor mailing list