Random Password Generator

import random 

# Characters that will be used to generate the password 
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*'

# Ask user for the length of the password
length = int(input('Enter the length of the password: '))

# Generate and print the random password
rand_pass = ''.join(random.sample(chars, length))
#The random.sample() function is used to randomly select a specified number of characters (length) from the chars string. 
#The resulting list of characters is then passed to the join() method of the empty string (''),
# which concatenates the characters into a single string. The resulting string is stored in the rand_pass variable.
print('Your randomly generated password is: ', rand_pass)

# Checks how easily guessed the password is
if len(rand_pass) > 15:
    print("Very strong password")
elif 9 < len(rand_pass) < 15:
    print("strong password")
elif 5 < len(rand_pass) < 9:
    print("decently strong password")
else:
    print("weak password")
Your randomly generated password is:  wKts6opxiXmquYazB&^e
Very strong password

This code generates a random password of a specified length and then checks how strong the password is based on its length.

The first line imports the random module, which provides functions for generating random numbers and selecting random elements from a list.

The chars string contains a list of all the characters that will be used to generate the password. This includes lowercase and uppercase letters, numbers, and special characters.

The code then asks the user to enter the desired length of the password using the input function. This value is converted to an integer using the int function and stored in the length variable.

The random.sample function is used to select length random characters from the chars string, and these characters are joined together using the join method of the string object to form the random password. This password is then printed to the screen.

Finally, the code uses an if statement to check the length of the password and print a message indicating how strong the password is. If the password is longer than 15 characters, it is considered a very strong password. If it is between 9 and 15 characters long, it is considered a strong password. If it is between 5 and 9 characters long, it is considered a decently strong password. Otherwise, it is considered a weak password.

Email Slicer

def email_slicer(email):
  # Split the email address at the '@' character
  username, domain = email.split('@')
  return username, domain

# Test the email slicer
print(email_slicer('john.doe@gmail.com')) 
('john.doe', 'gmail.com')

This email slicer uses the built-in split method to split the email address at the '@' character, and returns a tuple containing the username and domain name.

Note that this email slicer does not perform any validation on the input email address. It is up to you to ensure that the email address is in the correct format before calling the email slicer.

Adress Book

class AddressBook:
  def __init__(self):
    # Initialize an empty dictionary to store the contact details
    self.contacts = {}

  def create_contact(self, name, phone, email):
    # Add the contact details to the dictionary
    self.contacts[name] = {'phone': phone, 'email': email}

  def edit_contact(self, name, phone=None, email=None):
    # Check if the contact exists in the dictionary
    if name in self.contacts:
      # Update the phone and/or email if provided
      if phone:
        self.contacts[name]['phone'] = phone
      if email:
        self.contacts[name]['email'] = email
      return True
    else:
      return False

  def delete_contact(self, name):
    # Remove the contact from the dictionary if it exists
    if name in self.contacts:
      del self.contacts[name]
      return True
    else:
      return False

  def get_contacts(self):
    # Return a copy of the contacts dictionary
    return self.contacts.copy()

# Create a new address book
address_book = AddressBook()

# Add some contacts
address_book.create_contact('Nikhil Chakravarthula', '415-937-3746', 'nikhilchakravarthula14@gmail.com')
address_book.create_contact('Anitha Ganjam', '510-717-7990', 'anitha.ganjam@gmail.com')
address_book.create_contact('Prashanth Chakravarthula', '415-341-3968', 'prashanth.chakravarthula@gmail.com')

# Edit a contact
address_book.edit_contact('Nikhil Chakravarthula', email='Nikhilc@yahoo.com')

# Delete a contact
address_book.delete_contact('Anitha Ganjam')

# Get the contacts
print(address_book.get_contacts())  
{'Nikhil Chakravarthula': {'phone': '415-937-3746', 'email': 'Nikhilc@yahoo.com'}, 'Prashanth Chakravarthula': {'phone': '415-341-3968', 'email': 'prashanth.chakravarthula@gmail.com'}}

The AddressBook class has four methods: create_contact, edit_contact, delete_contact, and get_contacts.

The init method initializes an empty dictionary called contacts to store the contact details.

The create_contact method takes three arguments: name, phone, and email, and adds a new contact to the contacts dictionary with these details. The contact's name is used as the key, and the phone and email are stored as a dictionary value.

The edit_contact method takes three optional arguments: name, phone, and email. It checks if the contact with the specified name exists in the contacts dictionary, and if it does, it updates the phone and/or email if provided. If the contact does not exist, it returns False.

The delete_contact method takes a single argument: name, and removes the contact with the specified name from the contacts dictionary if it exists. If the contact does not exist, it returns False.

The get_contacts method returns a copy of the contacts dictionary.

To use the AddressBook class, you can create a new instance of the class and call the various methods to create, edit, delete, and retrieve contacts.

My own research I do.

pip install yfinance
Requirement already satisfied: yfinance in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (0.1.74)
Requirement already satisfied: requests>=2.26 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from yfinance) (2.27.1)
Requirement already satisfied: pandas>=0.24.0 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from yfinance) (1.5.2)
Requirement already satisfied: numpy>=1.15 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from yfinance) (1.21.5)
Requirement already satisfied: multitasking>=0.0.7 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from yfinance) (0.0.11)
Requirement already satisfied: lxml>=4.5.1 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from yfinance) (4.8.0)
Requirement already satisfied: pytz>=2020.1 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from pandas>=0.24.0->yfinance) (2021.3)
Requirement already satisfied: python-dateutil>=2.8.1 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from pandas>=0.24.0->yfinance) (2.8.2)
Requirement already satisfied: six>=1.5 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from python-dateutil>=2.8.1->pandas>=0.24.0->yfinance) (1.16.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.26->yfinance) (1.26.9)
Requirement already satisfied: idna<4,>=2.5 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.26->yfinance) (3.3)
Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.26->yfinance) (2.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /Users/nikhilchakravarthula/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.26->yfinance) (2022.5.18.1)
Note: you may need to restart the kernel to use updated packages.
import yfinance as yf
ticker = 'AAPL', 'AMZN', 'WMT', 'GOOGL', 'MSFT', 'MCD', 'NVDA', 'TSLA', 'COST', 'MA'
start_date = '2017-01-01' 
end_date = '2023-03-01' 

price = yf.download(ticker, start_date, end_date)['Adj Close']
print(price)
[*********************100%***********************]  10 of 10 completed
                  AAPL       AMZN        COST      GOOGL          MA  \
Date                                                                   
2017-01-03   27.174759  37.683498  141.645111  40.400501  101.818062   
2017-01-04   27.144337  37.859001  141.671738  40.388500  102.784187   
2017-01-05   27.282379  39.022499  144.465088  40.651001  103.578018   
2017-01-06   27.586529  39.799500  144.394089  41.260502  104.323471   
2017-01-09   27.839203  39.846001  142.744705  41.359001  104.120178   
...                ...        ...         ...        ...         ...   
2022-12-27  130.029999  83.040001  458.500000  87.389999  346.160004   
2022-12-28  126.040001  81.820000  452.989990  86.019997  341.950012   
2022-12-29  129.610001  84.180000  456.529999  88.449997  348.209991   
2022-12-30  129.929993  84.000000  456.500000  88.230003  347.730011   
2023-01-03  125.070000  85.820000  453.279999  89.120003  346.799988   

                   MCD        MSFT        NVDA        TSLA         WMT  
Date                                                                    
2017-01-03  103.605560   57.645370   25.147224   14.466000   61.081337  
2017-01-04  103.484283   57.387459   25.733931   15.132667   61.437180  
2017-01-05  103.674835   57.387459   25.080660   15.116667   61.570629  
2017-01-06  104.592926   57.884869   25.415922   15.267333   60.725479  
2017-01-09  104.307114   57.700634   26.446367   15.418667   61.125805  
...                ...         ...         ...         ...         ...  
2022-12-27  266.839996  236.960007  141.210007  109.099998  143.809998  
2022-12-28  265.109985  234.529999  140.360001  112.709999  141.289993  
2022-12-29  265.929993  241.009995  146.029999  121.820000  142.149994  
2022-12-30  263.529999  239.820007  146.139999  123.180000  141.789993  
2023-01-03  264.329987  239.580002  143.149994  108.099998  143.600006  

[1511 rows x 10 columns]
import matplotlib.pyplot as plt
price["AMZN"].plot(label="AMZNStock")
plt.title("AMZN")
plt.xlabel("year")
plt.ylabel("price")
Text(0, 0.5, 'price')

This code is using the yfinance package to download daily stock price data for a list of ticker symbols from Yahoo Finance. The yfinance package is a wrapper for the Yahoo Finance API that makes it easy to retrieve stock data.

The ticker symbols for the stocks to be downloaded are specified as a tuple of strings: 'AAPL', 'AMZN', 'WMT', 'GOOGL', 'MSFT', 'MCD', 'NVDA', 'TSLA', 'COST', 'MA'.

The start and end dates for the data to be downloaded are specified as strings in the format 'YYYY-MM-DD': '2017-01-01' and '2022-01-01', respectively.

The yf.download() function is then called with the ticker symbols, start date, and end date as arguments, and the resulting data is stored in a variable called price. The ['Adj Close'] attribute is used to select only the "Adjusted Close" price column from the data.

Finally, the price data is printed to the console using the print() function.

Then the next line chunk of code just plots Amazons stock into a graph.