Wednesday, December 14, 2022

Random Password Generator using Python

 Hello! Today we will be making a randon password generator using Python.

The program will accept an integer length of password to be generated.

Code:

import random

# Function to generate a password

def generate_password(length):

   password = ""

  # List of characters to choose from

  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+-=[]{};:'\"<>,.?/"

  

  # Generate a password of the specified length

  for i in range(length):

    password += random.choice(chars)

    

  # Return the generated password

  return password


# Test the password generator

print(generate_password(8))  # Output: eg. "w4V6Bh8#"

print(generate_password(12)) # Output: eg. "a3!fB5gL7@m9D"

print(generate_password(16)) # Output: eg. "g5J7Fp3#h4V1@m6D8"


This program defines a "generate_password()" function that takes a password length as an input and returns a randomly generated password of that length. The password is generated by choosing random characters from a list of allowed characters. You can modify the list of allowed characters to suit your needs.

Sunday, December 11, 2022

Challenges - Cartesian Product

 In this challenge we will find the cartesian product of 2 sets of numbers:

What is cartesian product?

It is the product of two sets: the product of set X and set Y is the set that contains all ordered pairs (x,y) for which x belongs to X and y belongs to Y.

We will use Pythons itertools module and import its product method to get its cartesian product.

The task:

The solution:

Challenge - finding the average the student given the list of grades

The Task:

The solution:

Methods used:

- Dictionary and Nested loops

The code is uploaded on github! check it out!

Challenge - Find the runner-up score

 In this hackerrank challenge, we will be finding the second from the highest score using Python's set datatype.

The task:

The solution:

Check the code out on Github!


Challenges - Permutation

 The term permutation refers to a mathematical calculation of the number of ways a particular set can be arranged. Put simply, a permutation is a word that describes the number of ways things can be ordered or arranged.

In this hackerrank challenge, we will determine permutation of a given integer using Python's list comprehension feature.

The challenge:

The solution:

The code is uploaded on github. Check it out!

https://github.com/ianarceo

Git and Github

 I will upload my exercises, projects and other future codes on Github! But first let's talk about the basics of Git and Github.

What is Git?

Git is a free nd open source distributed version control system. This is popular program/tool that developers use to track changes on their code and files (version control). This is useful for coordinating work among programmers who collaboratively developing source code during their software development.

What is Github?

Github is a code hosting platform for version control and collaboration. As said, this is where you host your code so you and others can work together on projects from anywhere. This is where you pull the code, make modification and merge/upload the file. You can also make branches of the code so you can implement some of your ideas without affecting the master codebase. Github will track the changes, and commits so everyone can monitor changes.

Git basic commands:

1. git config --global "user.name" and git config --global "user.email" - This set ups your username and email for use in Git.

2. git init - initialize a directory to become a git repository

3. git add [file/files] - files will be put on the staging area while waiting for the commit command

4. git clone [url] - clone/download a repository/ies from a hosted location via URL

5. git commit -m "descriptive message"

List here are just some basic commands for git. You can search or watch youtube videos for more information and tutorials.

Pushing a local repository to Github

1. You must have your local repository in your PC (use git init for creating a local repository

2. type in the command

    -git remote add origin [URL] - url is your created github repository

    -git branch -M main (create a main branch)

    -git push -u origin main (push files on main branch)

Challenges - Leap Year

 In this task, we will determine if the given year is a leap year or normal year. We can make our life easier because there is a Python calendar module that returns true if the year is a leap year by calling the isleap() method. But I will do it manually to practice my coding skill!

The task

The solution:


My first post! :)

Hello! During my learning journey in Python, I stumbled upon a website (hackerrank.com) where you can test your ability to solve simple to complex problems. I registered on that site and do some coding challenges. There are a lot of beginners, and seasoned coders testing their coding ability. Some users do one liner codes! they are awesome!

Tried some task and here are some that I have solved:

 

The solution


Here is another task:

The Solution:

Those are just some simple task. But hey, practice makes perfect!