Thursday, December 21, 2023
text generator
import random
class ArticleGenerator:
def __init__(self):
self.templates = [
"The {adj1} {noun} {verb} over the {adj2} {noun2}.",
"In a {adj1} turn of events, {noun} {verb} {adj2}ly.",
"{noun} {verb} {adj1}, making it a {adj2} story."
]
self.adjectives = ["quick", "lazy", "brown", "noisy", "blue", "green"]
self.nouns = ["fox", "dog", "head", "leg", "cat"]
self.verbs = ["jumps", "lifts", "bites", "licks", "kicks"]
self.nouns2 = ["table", "chair", "rug", "book", "shoe"]
def generate_article(self):
template = random.choice(self.templates)
adj1 = random.choice(self.adjectives)
adj2 = random.choice(self.adjectives)
noun = random.choice(self.nouns)
verb = random.choice(self.verbs)
noun2 = random.choice(self.nouns2)
article = template.format(adj1=adj1, adj2=adj2, noun=noun, verb=verb, noun2=noun2)
return article
# Example usage:
generator = ArticleGenerator()
for _ in range(5):
generated_article = generator.generate_article()
print(generated_article)
montage calculator
import tkinter as tk
from tkinter import messagebox
def calculate():
try:
amount = float(entry_amount.get())
years = int(entry_years.get())
interest_rate = float(entry_interest_rate.get()) / 100
total = amount * (1 + interest_rate * years)
messagebox.showinfo("ISA Calculator", f"Your ISA will be worth £{total:.2f} after {years} years.")
except ValueError:
messagebox.showerror("Error", "Please enter valid numbers.")
# Create the main window
root = tk.Tk()
root.title("ISA Calculator")
# Create labels
label_amount = tk.Label(root, text="Initial Amount:")
label_years = tk.Label(root, text="Number of Years:")
label_interest_rate = tk.Label(root, text="Interest Rate (%):")
label_amount.grid(row=0, column=0, padx=10, pady=5, sticky=tk.E)
label_years.grid(row=1, column=0, padx=10, pady=5, sticky=tk.E)
label_interest_rate.grid(row=2, column=0, padx=10, pady=5, sticky=tk.E)
# Create entry boxes
entry_amount = tk.Entry(root)
entry_years = tk.Entry(root)
entry_interest_rate = tk.Entry(root)
entry_amount.grid(row=0, column=1, padx=10, pady=5)
entry_years.grid(row=1, column=1, padx=10, pady=5)
entry_interest_rate.grid(row=2, column=1, padx=10, pady=5)
# Create calculate button
calculate_button = tk.Button(root, text="Calculate", command=calculate)
calculate_button.grid(row=3, columnspan=2, padx=10, pady=10)
# Run the main loop
root.mainloop()
function calculateMortgage() {
var loanAmount = parseFloat(document.getElementById('loanAmount').value);
var interestRate = parseFloat(document.getElementById('interestRate').value) / 100 / 12;
var loanTerm = parseFloat(document.getElementById('loanTerm').value) * 12;
var monthlyPayment = (loanAmount * interestRate) / (1 - Math.pow(1 + interestRate, -loanTerm));
var totalPayment = monthlyPayment * loanTerm;
var totalInterest = totalPayment - loanAmount;
displayResults(monthlyPayment, totalPayment, totalInterest);
}
function displayResults(monthlyPayment, totalPayment, totalInterest) {
var monthlyPaymentElement = document.getElementById('monthlyPayment');
var totalPaymentElement = document.getElementById('totalPayment');
var totalInterestElement = document.getElementById('totalInterest');
monthlyPaymentElement.textContent = 'Monthly Payment: $' + monthlyPayment.toFixed(2);
totalPaymentElement.textContent = 'Total Payment: $' + totalPayment.toFixed(2);
totalInterestElement.textContent = 'Total Interest: $' + totalInterest.toFixed(2);
}
Saturday, December 16, 2023
tag generator
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
import spacy
from collections import Counter
# Define stopwords and maximum number of hashtags
stop_words = stopwords.words("english")
max_hashtags = 5
# Load spaCy model
nlp = spacy.load("en_core_web_sm")
def generate_hashtags(text):
"""
Generates hashtags from a given text.
Args:
text: The text to analyze.
Returns:
A list of generated hashtags.
"""
# Lowercase and tokenize the text
tokens = word_tokenize(text.lower())
# Remove stopwords
filtered_tokens = [token for token in tokens if token not in stop_words]
# Extract named entities
doc = nlp(" ".join(filtered_tokens))
entities = [str(ent) for ent in doc.ents]
# Combine keywords and entities
potential_hashtags = filtered_tokens + entities
# Remove invalid characters and duplicates
valid_hashtags = [
hashtag.replace(" ", "_")
for hashtag in potential_hashtags
if hashtag.isalnum() and len(hashtag) <= 25
]
valid_hashtags = list(set(valid_hashtags))
# Count occurrences and select top hashtags
hashtag_counts = Counter(valid_hashtags)
top_hashtags = hashtag_counts.most_common(max_hashtags)
# Return a list of top hashtags
return [hashtag for hashtag, count in top_hashtags]
# Example usage
text = "This is a beautiful article about the Great Barrier Reef and its diverse marine life."
hashtags = generate_hashtags(text)
print(f"Generated hashtags: {hashtags}")
Subscribe to:
Posts (Atom)
screan recoder
Screen Recorder Screen Recorder Tool Start Recording Stop Recording...
-
import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servl...
-
Screen Recorder Screen Recorder Tool Start Recording Stop Recording...
-
import random class ArticleGenerator: def __init__(self): self.templates = [ "The {adj1} {noun} {verb} over th...