Skip to content

Commit

Permalink
Merge pull request #161 from djv554/main
Browse files Browse the repository at this point in the history
Added new beginner level projects
  • Loading branch information
UTSAVS26 authored Oct 7, 2024
2 parents 7959da6 + 2b89a90 commit 4a61f66
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Beginner_Projects/Number Guessing Game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## **Password Generator**

### 🎯 **Goal**

The goal of this project is to create a simple number guessing game using Streamlit.

### 🧵 **Dataset**

N/A

### 🧾 **Description**

This project is a Number Guessing Game where the computer generates a random number between 1 and 100, and the player tries to guess it. It implements some fundamental programming concepts of Python. It provides an engaging, interactive experience where users can repeatedly guess until they find the correct number, offering immediate feedback.

### 🧮 **What I had done!**

1. Built a simple Streamlit interface for users to guess a number between 1-100
2. The game continues indefinitely until the correct number is guessed. If the guess is too low, it prompts the player to try again. If the guess is too high, it prompts the player to try again.
3. If the guess is correct, the player is congratulated, the number of attempts is displayed, and the loop ends.


### 🚀 **Models Implemented**

N/A

### 📚 **Libraries Needed**

1. `Streamlit` - For building the user interface.
2. `random` - To randomly select a number for the user to guess

### 📊 **Exploratory Data Analysis Results**

N/A.

### 📈 **Performance of the Models based on the Accuracy Scores**

N/A.

### 📢 **Conclusion**

In conclusion, this Number Guessing Game project demonstrates fundamental programming concepts such as random number generation, user input handling, loops, and error handling in Python. It provides an engaging, interactive experience where users can repeatedly guess until they find the correct number, offering immediate feedback. The code is simple yet effective, making it a great learning project for beginner developers looking to strengthen their understanding of basic programming logic.

**Deanne Vaz**
[GitHub](https://github.com/djv554) | | [LinkedIn](https://www.linkedin.com/in/deanne-vaz/)
43 changes: 43 additions & 0 deletions Beginner_Projects/Number Guessing Game/number_guessing_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import streamlit as st
import random

def number_guessing_game():
st.title("Number Guessing Game")

# Initialize session state to store target number and attempts
if "target_number" not in st.session_state:
st.session_state.target_number = random.randint(1, 100)
st.session_state.attempts = 0
st.session_state.game_over = False

# Game instructions
st.write("Guess the number I'm thinking of! It's between 1 and 100.")

# Input form for user guesses
with st.form("guess_form"):
guess = st.number_input("Enter your guess:", min_value=1, max_value=100, step=1)
submitted = st.form_submit_button("Submit Guess")

if submitted:
if st.session_state.game_over:
st.warning("The game is over! Click the 'Restart' button to play again.")
else:
st.session_state.attempts += 1
if guess < st.session_state.target_number:
st.warning("Too low! Try again.")
elif guess > st.session_state.target_number:
st.warning("Too high! Try again.")
else:
st.success(f"Congratulations! You guessed the number in {st.session_state.attempts} attempts.")
st.session_state.game_over = True

# Restart button to start a new game
if st.button("Restart"):
st.session_state.target_number = random.randint(1, 100)
st.session_state.attempts = 0
st.session_state.game_over = False
st.info("New game started! Guess the new number.")

# Run the game
if __name__ == "__main__":
number_guessing_game()
43 changes: 43 additions & 0 deletions Beginner_Projects/Web Scraper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## **Password Generator**

### 🎯 **Goal**

The goal of this code is to create a simple web scraper that extracts article titles from a specified website.

### 🧵 **Dataset**

N/A

### 🧾 **Description**

This code is a web scraper that extracts article titles from a user-specified website. It prompts the user to enter a URL, sends an HTTP GET request while simulating a web browser, and checks for a successful response. If successful, it parses the HTML content to find and print headings (h2 and h3 tags) that typically contain article titles. The tool is designed to efficiently gather information from online news sources or similar content-rich websites.

### 🧮 **What I had done!**

1. User Interaction: The script prompts the user to enter a website URL, making it dynamic and user-friendly.
2. Error Handling: Basic error handling by checking the HTTP response status and handling cases where no titles are found.
3. Accepts a URL as input. Prints the extracted titles to the console.

### 🚀 **Models Implemented**

N/A

### 📚 **Libraries Needed**

1. `requests` - This library is used to send HTTP requests to the specified URL and retrieve the content of the webpage.
2. `BeautifulSoup` from `bs4` - This library is part of the Beautiful Soup package, which is used for parsing HTML and XML documents. It allows you to navigate and search through the parse tree to extract the desired data.

### 📊 **Exploratory Data Analysis Results**

N/A.

### 📈 **Performance of the Models based on the Accuracy Scores**

N/A.

### 📢 **Conclusion**

In conclusion, this web scraping code effectively allows users to extract article titles from any specified website by leveraging the requests library for making HTTP requests and BeautifulSoup for parsing HTML content. By providing a user-friendly interface for inputting a URL, the script enables quick and efficient access to relevant headlines, making it a useful tool for gathering information from online news sources and similar content-rich websites. Overall, it demonstrates a practical application of web scraping techniques for data collection and analysis.

**Deanne Vaz**
[GitHub](https://github.com/djv554) | | [LinkedIn](https://www.linkedin.com/in/deanne-vaz/)
40 changes: 40 additions & 0 deletions Beginner_Projects/Web Scraper/web_scraper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import requests
from bs4 import BeautifulSoup

# Function to scrape article titles from a specified website
def scrape_titles(url):
# Set headers to mimic a browser
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"
}

# Send a GET request to the website
response = requests.get(url, headers=headers)

# Check if the request was successful
print("HTTP Status Code:", response.status_code) # Debugging print
if response.status_code == 200:
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')

# Find all headings (h2, h3, etc.) - you can modify the tag selection here
titles = soup.find_all(['h2', 'h3'])

# Extract and print the titles
print("Article Titles from", url)
found_titles = False
for idx, title in enumerate(titles):
text = title.get_text()
if text: # Check if there's text in the heading
print(f"{idx + 1}. {text.strip()}")
found_titles = True

if not found_titles:
print("No article titles found.")
else:
print("Failed to retrieve the webpage. Status code:", response.status_code)

# Main block to get URL input from the user
if __name__ == "__main__":
website_url = input("Enter the URL of the website to scrape: ")
scrape_titles(website_url)

0 comments on commit 4a61f66

Please sign in to comment.