mercredi 4 août 2021

In Python how can i draw a pattern without using any third party libraries ,and the sequence of input

I need to draw a pattern in the image given below without using any libraries in python . Kindly help

Input : 3 4 3 4 5 1 9 2 2 4 Image : https://i.stack.imgur.com/HJykN.png

Below is the code i tried but it does not working

def triangle(*args):
    main=[]
    for num in range(len(args)):
        k = args[num] - 1
        patt = []
        for i in range(0, args[num]):
            hello = ''
            for j in range(0, k):
                hello = hello + " "
            if num%2==0:
                k = k - 1
                hello = hello+"/"
            else:
                k = k+ 1
                hello = hello + "\\"
            patt.append(hello)
        main.append(patt)
    return main
lists = triangle(3,4,3)

Aucun commentaire:

Enregistrer un commentaire