Skip to main content

Day-1 Create an equilateral triangle pattern (PYRAMID) with stars using python

                                                                     FIRST


With no space in between the stars:

def space(n,i):
    c=n-i
    if c>0:
        print(" "*c, end="")

def star(i):
    if i>0:
        print("*"*(2*i-1), end="")

def start():
    n=int(input("Enter the rows: "))
    b=n
    i=1
    while n>0: #3
         #1
        space(b,i)# 1 2 3 
        star(i)
        space(b,i)
        print()
        i=i+1
        n=n-1

start()

Let's go through the code step by step:

  1. The space() function takes two parameters, n and i, which represent the total number of spaces (n) and the current row number (i).

  2. Inside the space() function, the variable c is calculated as the difference between n and i, representing the number of spaces needed in the current row.

  3. If c is greater than 0, a space character is printed c number of times using the " "*c expression. The end="" parameter is used to avoid printing a newline character.

  4. The star() function takes the i parameter, representing the current row number.

  5. If i is greater than 0, the expression "*" is multiplied by (2*i-1), which gives the number of stars in the current row. This ensures that the number of stars follows the pattern of an equilateral triangle.

  6. Inside the start() function, the number of rows n is obtained from user input using input() and int() functions.

  7. The variable b is assigned the value of n to store the initial number of spaces needed.

  8. The variable i is initialized to 1, representing the current row number.

  9. The while loop executes as long as n is greater than 0, indicating there are more rows to print.

  10. Inside the loop, the space() function is called with b and i as arguments to print the required number of spaces before the stars in each row.

  11. The star() function is called with i as an argument to print the stars in each row.

  12. After printing the stars, the space() function is called again with b and i as arguments to print the spaces after the stars.

  13. A newline character is printed using print() to move to the next row.

  14. The variables i and n are incremented and decremented, respectively, to move to the next row.

  15. The while loop continues until all rows are printed.


SECOND


With  space in between the stars:

def space(n, i):
    c = n - i
    if c > 0:
        print(" " * c, end=" ")

def star(i):
    if i > 0:
        print("* " * i, end="")

def start():
    n = int(input("Enter the rows: "))
    b = n
    i = 1
    while n > 0:
        space(b, i)
        star(i)
        space(b, i)
        print()
        i += 1
        n -= 1

start()

The changes made are:

  1. In the space function, an extra space character is added after printing the spaces to achieve the desired spacing between the spaces and the stars.
  2. In the star function, the "*" is followed by a space character to achieve the desired spacing between the stars.

Now let's try something different:



def space(n,i):
    c=n-i
    if(c>0):
        print(" "*c, end="")
       
def star(i):
    if(i>0):
        print("* "*(2*i-1), end="")

def start():
    n=int(input("Enter the rows: "))
    b=n
    i=1
    while n>0:
        space(b,i)
        star(i)
        space(b,i)
        print()
        i=i+1
        n=n-1

start()



Comments

Popular posts from this blog

Bug Boundy Methodology, Tools & Resources

Start by defining a clear objective, such as exploiting a remote code execution (RCE) vulnerability or bypassing authentication on your target. Then, consider how you can achieve this goal using various attack vectors like XSS, SSRF, or others - these are simply tools to help you reach your objective. Use the target as how a normal user would, while browsing keep these questions in mind: 1)How does the app pass data? 2)How/where does the app talk about users? 3)Does the app have multi-tenancy or user levels? 4)Does the app have a unique threat model? 5)Has there been past security research & vulnerabilities? 6)How does the app handle XSS, CSRF, and code injection?

Install & set up mitmweb or mitmproxy in Linux

Step 1: Go to the mitmproxy page and download the binaries. Step 2: Install the downloaded tar file with the command " tar -xzf <filename>.tar.gz " Step 3: In the FoxyProxy add the proxy 127.0.0.1:8080  and turn it on. Step 4 : In the terminal run command " ./mitmweb " Step 5: Go to the page  http://mitm.it/   and download the mitmproxy's Certificate. Step 6: If you downloaded the certificate for Firefox, then go to " settings -> Privacy & Security -> Click View Certificates -> Click  Import ", then import the certificate.  Step 7: Now you are ready to capture the web traffic. Step 8 : In terminal run " ./mitmweb"

Making CHIP-8 emulator in C

  Chip8 doc link | Components | Opcode Table GitHub - AdithyakrishnaV/Chip8_Emulator--Interpreter Contribute to AdithyakrishnaV/Chip8_Emulator--Interpreter development by creating an account on GitHub. github.com CHIP-8 programs are binary files, and your emulator must read them and operate on the bytes. You will also need a way to draw graphics to the screen and read keypresses. Many graphical libraries can do this for you or use something like SDL directly. CHIP-8 components Display 64 pixels wide and 32 pixels tall. Each pixel is a boolean value, or a bit; can be on or off (“off” pixel was just black, and “on” was white). We’ll use SDL for rendering: SDL initialization Not initialize:- returns -1  Error message is stored in SDL_GetError Initializing SDL if (SDL_Init(SDL_INIT_VIDEO)!= 0 ){ printf ( "SDL not initialized,%s\n" , SDL_GetError); exit (- 1 ); } Initialize display SDL_Window * window = SDL_CreateWindow ( "chip8" , SDL_WINDOWPOS_CENTERED , SDL_...