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"

API Bug Bounty Hunting: Reconnaissance and Reverse Engineering an API

  In order to target APIs, you must first be able to find them.APIs meant for consumer use are meant to be easily discovered. Typically, the API provider will market their API to developers who want to be consumers. So, it will often be very easy to find APIs, just by using a web application as an end-user. The goal here is to find APIs to attack and this can be accomplished by discovering the API itself or the API documentation. Bug Boundy Methodology, Tools & Resources Start by defining a clear objective, such as exploiting a remote code execution (RCE) vulnerability or bypassing… adithyakrishnav.blogspot.com Reconnaissance Passive Reconnaissance It is obtaining information about a target without directly interacting with the target’s systems. Google Dorking Firstly, google search for “<app name> API”. intitle:” api” site:”google.com” inurl:”/api/v2" site:”google.com” inurl:”/api/v1" intext:”index of /” inurl:json site:”google.com” intitle:”index.of” intext:”api.t...