-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
359a611
commit 1994d85
Showing
8 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# asking for input from the users | ||
the_height = float(input("Enter the height in cm: ")) | ||
the_weight = float(input("Enter the weight in kg: ")) | ||
# defining a function for BMI | ||
the_BMI = the_weight / (the_height/100)**2 | ||
# printing the BMI | ||
print("Your Body Mass Index is", the_BMI) | ||
# using the if-elif-else conditions | ||
if the_BMI <= 18.5: | ||
print("Oops! You are underweight.") | ||
elif the_BMI <= 24.9: | ||
print("Awesome! You are healthy.") | ||
elif the_BMI <= 29.9: | ||
the_print("Eee! You are over weight.") | ||
else: | ||
print("Seesh! You are obese.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 5655565 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import random | ||
password = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz" | ||
length_possword = int(input("Enter your password length: ")) | ||
a = "" .join(random.sample(password, length_possword)) | ||
|
||
print(f"your password is{a}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import requests | ||
|
||
def get_weather_data(api_key, location): | ||
url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=imperial" | ||
response = requests.get(url) | ||
|
||
if response.status_code == 200: | ||
data = response.json() | ||
F = data['main']['temp'] | ||
humidity = data['main']['humidity'] | ||
description = data['weather'][0]['description'] | ||
|
||
return F, humidity, description | ||
else: | ||
print(f"Error: Unable to fetch weather data for '{location}'.") | ||
return None, None, None | ||
|
||
|
||
if __name__ == "__main__": | ||
api_key = "6ddec2f560686e41e571e8cd7fe99e48" | ||
location = input("Enter the city name or ZIP code: ") | ||
|
||
F, humidity, description = get_weather_data(api_key, location) | ||
|
||
if F is not None: | ||
print(f"Fahrenheit: {F}°F") | ||
print(f"Humidity: {humidity}%") | ||
print(f"Description: {description.capitalize()}") | ||
|
||
C = (F - 32) * 5/9 | ||
print(f"Celsius: {C}°C") |
33 changes: 33 additions & 0 deletions
33
Oasis infobyte project/chat application/chat aplication client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import socket | ||
import threading | ||
|
||
nickname = input("Enter your nickname: ") | ||
def receive_message(client_socket): | ||
while True: | ||
try: | ||
message = client_socket.recv(1024).decode('ascii') | ||
if message == 'NICK': | ||
client_socket.send(input('Enter your nickname: ').encode('ascii')) | ||
else: | ||
print(message) | ||
except: | ||
print("An error occurred!") | ||
client_socket.close() | ||
break | ||
|
||
def main(): | ||
host = 'localhost' | ||
port = 12345 | ||
|
||
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
client_socket.connect((host, port)) | ||
|
||
receive_thread = threading.Thread(target=receive_message, args=(client_socket,)) | ||
receive_thread.start() | ||
|
||
while True: | ||
message = f'{nickname}: {input("")}'.encode('ascii') | ||
client_socket.send(message) | ||
|
||
if __name__ == "__main__": | ||
main() |
47 changes: 47 additions & 0 deletions
47
Oasis infobyte project/chat application/chat aplication server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import socket | ||
import threading | ||
|
||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
server.bind(('localhost', 12345)) | ||
server.listen(2) | ||
|
||
clients = [] | ||
nicknames = [] | ||
|
||
def broadcast(message): | ||
for client in clients: | ||
client.send(message) | ||
|
||
def handle(client): | ||
while True: | ||
try: | ||
message = client.recv(1024) | ||
broadcast(message) | ||
except: | ||
index = clients.index(client) | ||
clients.remove(client) | ||
client.close() | ||
nickname = nicknames[index] | ||
nicknames.remove(nickname) | ||
broadcast(f'{nickname} left the chat!'.encode('ascii')) | ||
break | ||
|
||
def receive(): | ||
while True: | ||
client, address = server.accept() | ||
print(f'Connected with {str(address)}') | ||
|
||
client.send('NICK'.encode('ascii')) | ||
nickname = client.recv(1024).decode('ascii') | ||
nicknames.append(nickname) | ||
clients.append(client) | ||
|
||
print(f'Nickname of client is {nickname}!') | ||
broadcast(f'{nickname} joined the chat!'.encode('ascii')) | ||
client.send('Connected to the server!'.encode('ascii')) | ||
|
||
thread = threading.Thread(target=handle, args=(client,)) | ||
thread.start() | ||
|
||
print("Chat Server is running...") | ||
receive() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
home = C:\Users\ankit\AppData\Local\Programs\Python\Python312 | ||
include-system-site-packages = false | ||
version = 3.12.3 | ||
executable = C:\Users\ankit\AppData\Local\Programs\Python\Python312\python.exe | ||
command = C:\Users\ankit\AppData\Local\Programs\Python\Python312\python.exe -m venv c:\Users\ankit\Desktop\internship project 1\.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import speech_recognition as sr | ||
import pyttsx3 | ||
import datetime | ||
import webbrowser | ||
import requests | ||
|
||
# Initialize the recognizer and the text-to-speech engine | ||
recognizer = sr.Recognizer() | ||
tts_engine = pyttsx3.init() | ||
|
||
# OpenWeatherMap API key | ||
API_KEY = '6ddec2f560686e41e571e8cd7fe99e48' | ||
WEATHER_URL = 'http://api.openweathermap.org/data/2.5/weather' | ||
|
||
# Function to convert text to speech | ||
def speak(text): | ||
tts_engine.say(text) | ||
tts_engine.runAndWait() | ||
|
||
# Function to recognize speech and convert it to text | ||
def listen(): | ||
with sr.Microphone() as source: | ||
print("Listening...") | ||
recognizer.adjust_for_ambient_noise(source) | ||
audio = recognizer.listen(source) | ||
try: | ||
print("Recognizing...") | ||
command = recognizer.recognize_google(audio) | ||
print(f"User said: {command}\n") | ||
return command.lower() | ||
except sr.UnknownValueError: | ||
speak("Sorry, I did not understand that.") | ||
return "" | ||
except sr.RequestError: | ||
speak("Sorry, my speech service is down.") | ||
return "" | ||
|
||
# Function to tell the current time | ||
def tell_time(): | ||
now = datetime.datetime.now() | ||
current_time = now.strftime("%I:%M %p") | ||
speak(f"The time is {current_time}") | ||
|
||
# Function to tell the current date | ||
def tell_date(): | ||
today = datetime.date.today() | ||
speak(f"Today's date is {today.strftime('%B %d, %Y')}") | ||
|
||
# Function to perform a web search | ||
def search_web(query): | ||
url = f"https://www.google.com/search?q={query}" | ||
webbrowser.get().open(url) | ||
speak(f"Here are the search results for {query}") | ||
|
||
# Function to get weather information | ||
def get_weather(city): | ||
params = { | ||
'q': city, | ||
'appid': API_KEY, | ||
'units': 'metric' # Use 'imperial' for Fahrenheit | ||
} | ||
response = requests.get(WEATHER_URL, params=params) | ||
if response.status_code == 200: | ||
data = response.json() | ||
weather = data['weather'][0]['description'] | ||
temperature = data['main']['temp'] | ||
speak(f"The current weather in {city} is {weather} with a temperature of {temperature} degrees Celsius.") | ||
else: | ||
speak("Sorry, I couldn't retrieve the weather information.") | ||
|
||
# Main function to handle voice commands | ||
def handle_command(command): | ||
if "hello" in command: | ||
speak("Hello! How can I assist you today?") | ||
elif "time" in command: | ||
tell_time() | ||
elif "date" in command: | ||
tell_date() | ||
elif "search" in command: | ||
query = command.replace("search", "").strip() | ||
search_web(query) | ||
elif "weather" in command: | ||
city = command.replace("weather in", "").strip() | ||
get_weather(city) | ||
else: | ||
speak("Sorry, I can only respond to simple commands like 'hello', 'time', 'date', 'search', and 'weather'.") | ||
|
||
# Run the assistant in a loop to continuously listen for commands | ||
def run_assistant(): | ||
speak("Voice assistant activated. How can I help you?") | ||
while True: | ||
command = listen() | ||
if "exit" in command or "stop" in command: | ||
speak("Goodbye") | ||
break | ||
handle_command(command) | ||
|
||
# Start the voice assistant | ||
if __name__ == "__main__": | ||
run_assistant() |