Python Intenship
Python Intenship
Python Intenship
import datetime
FILE_NAME = "tasks.json"
def load_tasks():
try:
return json.load(f)
return []
def save_tasks(tasks):
json.dump(tasks, f, indent=4)
def add_task():
task = {
"title": title,
"due_date": due_date,
"priority": priority
}
tasks = load_tasks()
tasks.append(task)
save_tasks(tasks)
def view_tasks():
tasks = load_tasks()
if not tasks:
return
def delete_task():
view_tasks()
try:
tasks = load_tasks()
del tasks[task_num - 1]
save_tasks(tasks)
else:
except ValueError:
def main():
while True:
print("\nTo-Do List")
print("4. Exit")
if choice == "1":
add_task()
view_tasks()
delete_task()
print("Exiting...")
break
else:
if __name__ == "__main__":
main()
Output:
To-Do List
1. Add Task
2. View Tasks
3. Delete Task
4. Exit
Choose an option: 1
To-Do List
1. Add Task
2. View Tasks
3. Delete Task
4. Exit
Choose an option: 1
To-Do List
1. Add Task
2. View Tasks
3. Delete Task
4. Exit
Choose an option: 1
To-Do List
1. Add Task
2. View Tasks
3. Delete Task
4. Exit
Choose an option: 2
1. calculator in python program (Due: 2024-11-16, Priority: high)
To-Do List
1. Add Task
2. View Tasks
3. Delete Task
4. Exit
Choose an option: 3
To-Do List
1. Add Task
2. View Tasks
3. Delete Task
4. Exit
Choose an option: 2
To-Do List
1. Add Task
2. View Tasks
3. Delete Task
4. Exit
Choose an option: 4
Exiting...
2. Calculator: Build a basic calculator program that can perform arithmetic
operations (addition, subtraction, multiplication, division) based on user
input.
Program to calculator:
# pip install tkinter
import tkinter as tk
import tkinter.messagebox
window = tk.Tk()
window.title('Calculator')
frame.pack()
def myclick(number):
entry.insert(tk.END, number)
def equal():
try:
y = str(eval(entry.get()))
entry.delete(0, tk.END)
entry.insert(0, y)
except:
entry.delete(0, tk.END)
button_subtract = tk.Button(
button_multiply = tk.Button(
window.mainloop()
output:
3. Weather App: Develop a program that fetches weather data from an online
API and displays it to the user based on their location or a user-provided
location.
import tkinter as tk
import tkinter.messagebox
#GUI
root = tk.Tk()
root.title("Currency converter:GeeksForGeeks")
Tops.grid(row=0, column=0)
headlabel = tk.Label(Tops, font=('lato black', 19, 'bold'), text='Currency converter :GeeksForGeeks ',
bg='#e6e5e5', fg='black')
variable1 = tk.StringVar(root)
variable2 = tk.StringVar(root)
variable1.set("currency")
variable2.set("currency")
def RealTimeCurrencyConversion():
c = CurrencyRates()
from_currency = variable1.get()
to_currency = variable2.get()
if (Amount1_field.get() == ""):
tkinter.messagebox.showinfo("Error !!",
else:
new_amount = float("{:.4f}".format(new_amt))
Amount2_field.insert(0, str(new_amount))
def clear_all():
Amount1_field.delete(0, tk.END)
Amount2_field.delete(0, tk.END)
root.configure(background='#e6e5e5')
root.geometry("700x400")
Label_1 = Label(root, font=('lato black', 27, 'bold'), text="", padx=2, pady=2, bg="#e6e5e5",
fg="black")
label1 = tk.Label(root, font=('lato black', 15, 'bold'), text="\t Amount : ", bg="#e6e5e5", fg="black")
label1 = tk.Label(root, font=('lato black', 15, 'bold'), text="\t To Currency : ", bg="#e6e5e5",
fg="black")
label1 = tk.Label(root, font=('lato black', 15, 'bold'), text="\t Converted Amount : ", bg="#e6e5e5",
fg="black")
Amount1_field = tk.Entry(root)
Amount2_field = tk.Entry(root)
command=RealTimeCurrencyConversion)
Label_9.grid(row=6, column=0)
Label_9 = Button(root, font=('arial', 15, 'bold'), text=" Clear All ", padx=2, pady=2, bg="lightblue",
fg="white",
command=clear_all)
Label_9.grid(row=10, column=0)
root.mainloop()
Output:
symbols).
import string
import random
1. Digits
2. Letters
3. Special characters
4. Exit''')
characterList = ""
while(True):
if(choice == 1):
characterList += string.ascii_letters
elif(choice == 2):
characterList += string.digits
elif(choice == 3):
# characters
characterList += string.punctuation
elif(choice == 4):
break
else:
password = []
for i in range(length):
# character list
randomchar = random.choice(characterList)
password.append(randomchar)
OUTPUT:
1. Digits
2. Letters
3. Special characters
4. Exit
Pick a number 1
Pick a number 2
Pick a number 3
Pick a number 4
6. Simple Blog System: Create a simple blog system where users can write,
edit, and delete blog posts. Store blog posts in text files or a lightweight
database.
Program to create a simple Blog system:
import os
import getpass
# Blog data stored in dictionaries
users = {}
posts = {}
comments = {}
def register():
username = input("Enter username: ")
password = getpass.getpass("Enter password: ")
users[username] = password
print("Registration successful!")
def login():
username = input("Enter username: ")
password = getpass.getpass("Enter password: ")
if username in users and users[username] == password:
return username
else:
print("Invalid credentials.")
return None
def create_post(username):
title = input("Enter post title: ")
content = input("Enter post content: ")
posts[title] = {"author": username, "content": content}
print("Post created!")
def view_posts():
for title, post in posts.items():
print(f"Title: {title}")
print(f"Author: {post['author']}")
print(f"Content: {post['content']}\n")
def edit_post(username):
title = input("Enter post title: ")
if title in posts and posts[title]["author"] == username:
content = input("Enter new content: ")
posts[title]["content"] = content
print("Post updated!")
else:
print("Post not found or unauthorized.")
def delete_post(username):
title = input("Enter post title: ")
if title in posts and posts[title]["author"] == username:
del posts[title]
print("Post deleted!")
else:
print("Post not found or unauthorized.")
def comment_post():
title = input("Enter post title: ")
if title in posts:
comment = input("Enter comment: ")
if title not in comments:
comments[title] = []
comments[title].append(comment)
print("Comment added!")
else:
print("Post not found.")
def view_comments():
title = input("Enter post title: ")
if title in comments:
print("Comments:")
for comment in comments[title]:
print(comment)
else:
print("No comments.")
def main():
while True:
print("1. Register")
print("2. Login")
print("3. Create Post")
print("4. View Posts")
print("5. Edit Post")
print("6. Delete Post")
print("7. Comment Post")
print("8. View Comments")
print("9. Quit")
choice = input("Choose an option: ")
if choice == "1":
register()
elif choice == "2":
username = login()
if username:
print(f"Welcome, {username}!")
elif choice == "3":
username = input("Enter username: ")
create_post(username)
elif choice == "4":
view_posts()
elif choice == "5":
username = input("Enter username: ")
edit_post(username)
elif choice == "6":
username = input("Enter username: ")
delete_post(username)
elif choice == "7":
comment_post()
elif choice == "8":
view_comments()
elif choice == "9":
break
else:
print("Invalid choice.")
if __name__ == "__main__":
main()
Output:
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 1
Enter username: chinni
Enter password: Chinni@4118
Registration successful!
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 2
Enter username: Chinni
Enter password: Chinni@4118
Invalid credentials.
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 3
Enter username: Chinni
Enter post title: task
Enter post content: python program
Post created!
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 4
Title: task
Author: Chinni
Content: python program
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 5
Enter username: Chinni
Enter post title: python taskl
Post not found or unauthorized.
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 4
Title: task
Author: Chinni
Content: python program
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 7
Enter post title: Python task
Post not found.
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 8
Enter post title: Python program
No comments.
1. Register
2. Login
3. Create Post
4. View Posts
5. Edit Post
6. Delete Post
7. Comment Post
8. View Comments
9. Quit
Choose an option: 9
7. Chat Application: Develop a basic chat application that allows users to send
and receive messages in real-time using sockets or a simple web interface .
Python program to develop Chat Application:
9. Quiz Game: Create a quiz game with multiple-choice questions. Keep track
of the player's score and provide feedback on their performance.
Program to create a quiz game:
from tkinter import *
# define question dictionary
question = {
"20+13": ['2', '33', '5', '9'],
"22-12": ['2', '10', '5'],
"10+3": ['13', '6', '9', '7'],
"15*2":['30','10','40','15'],
"100/4":['25','10','15','4']
}
# define answer list
ans = ['33', '10', '13','30','25']
current_question = 0
def start_quiz():
start_button.forget()
next_button.pack()
next_question()
def next_question():
global current_question
if current_question < len(question):
# get key or question that need to be printed
check_ans()
user_ans.set('None')
c_question = list(question.keys())[current_question]
# clear frame to update its content
clear_frame()
# printing question
Label(f1, text=f"Question : {c_question}", padx=15,
font="calibre 12 normal").pack(anchor=NW)
# printing options
for option in question[c_question]:
Radiobutton(f1, text=option, variable=user_ans,
value=option, padx=28).pack(anchor=NW)
current_question += 1
else:
next_button.forget()
check_ans()
clear_frame()
output = f"Your Score is {user_score.get()} out of {len(question)}"
Label(f1, text=output, font="calibre 25 bold").pack()
Label(f1, text="Thanks for Participating",
font="calibre 18 bold").pack()
def check_ans():
temp_ans = user_ans.get()
if temp_ans != 'None' and temp_ans == ans[current_question-1]:
user_score.set(user_score.get()+1)
def clear_frame():
for widget in f1.winfo_children():
widget.destroy()
if __name__ == "__main__":
root = Tk()
# setup basic window
root.title("GFG QUIZ APP")
root.geometry("850x520")
root.minsize(800, 400)
user_ans = StringVar()
user_ans.set('None')
user_score = IntVar()
user_score.set(0)
f1 = Frame(root)
f1.pack(side=TOP, fill=X)
root.mainloop()
Output:
10. Alarm Clock: Design an alarm clock application that allows users to set
alarms with specific times and messages. It can play a sound or display a
message when the alarm goes off.
Program to design a Alarm Clock:
# Import Required Library
from tkinter import *
import datetime
import time
import winsound
from threading import *
# Create Object
root = Tk()
# Set geometry
root.geometry("400x200")
# Use Threading
def Threading():
t1=Thread(target=alarm)
t1.start()
def alarm():
# Infinite Loop
while True:
# Set Alarm
set_alarm_time = f"{hour.get()}:{minute.get()}:{second.get()}"
frame = Frame(root)
frame.pack()
hour = StringVar(root)
hours = ('00', '01', '02', '03', '04', '05', '06', '07',
'08', '09', '10', '11', '12', '13', '14', '15',
'16', '17', '18', '19', '20', '21', '22', '23', '24'
)
hour.set(hours[0])
minute = StringVar(root)
minutes = ('00', '01', '02', '03', '04', '05', '06', '07',
'08', '09', '10', '11', '12', '13', '14', '15',
'16', '17', '18', '19', '20', '21', '22', '23',
'24', '25', '26', '27', '28', '29', '30', '31',
'32', '33', '34', '35', '36', '37', '38', '39',
'40', '41', '42', '43', '44', '45', '46', '47',
'48', '49', '50', '51', '52', '53', '54', '55',
'56', '57', '58', '59', '60')
minute.set(minutes[0])
second = StringVar(root)
seconds = ('00', '01', '02', '03', '04', '05', '06', '07',
'08', '09', '10', '11', '12', '13', '14', '15',
'16', '17', '18', '19', '20', '21', '22', '23',
'24', '25', '26', '27', '28', '29', '30', '31',
'32', '33', '34', '35', '36', '37', '38', '39',
'40', '41', '42', '43', '44', '45', '46', '47',
'48', '49', '50', '51', '52', '53', '54', '55',
'56', '57', '58', '59', '60')
second.set(seconds[0])
# Execute Tkinter
root.mainloop()
Output:
11.Basic Web Scraper: Write a web scraper that extracts data from a website
of interest. You can use libraries like BeautifulSoup and requests for this task.
Program to write web Scaper:
13. Expense Tracker: Develop a program that helps users track their daily
expenses.Users should be able to add expenses, categorize them, and view
summaries.
Program to write expense tracker:
# initializing string
test_string = "python programming is simple and can be easy to understand"
# printing result
print("The number of words in string are : " + str(res))
Output:
The original string is : python programming is simple and can be easy to understand
The number of words in string are : 10
def add():
# accepting input from the user
username = entryName.get()
# accepting password input from the user
password = entryPassword.get()
if username and password:
with open("passwords.txt", 'a') as f:
f.write(f"{username} {password}\n")
messagebox.showinfo("Success", "Password added !!")
else:
messagebox.showerror("Error", "Please enter both the fields")
def get():
# accepting input from the user
username = entryName.get()
if passwords:
mess = "Your passwords:\n"
for i in passwords:
if i == username:
mess += f"Password for {username} is {passwords[i]}\n"
break
else:
mess += "No Such Username Exists !!"
messagebox.showinfo("Passwords", mess)
else:
messagebox.showinfo("Passwords", "EMPTY LIST!!")
def delete():
# accepting input from the user
username = entryName.get()
messagebox.showinfo(
"Success", f"User {username} deleted successfully!")
except Exception as e:
messagebox.showerror("Error", f"Error deleting user {username}: {e}")
if __name__ == "__main__":
app = tk.Tk()
app.geometry("560x270")
app.title("Password Manager")
# Username block
labelName = tk.Label(app, text="USERNAME:")
labelName.grid(row=0, column=0, padx=15, pady=15)
entryName = tk.Entry(app)
entryName.grid(row=0, column=1, padx=15, pady=15)
# Password block
labelPassword = tk.Label(app, text="PASSWORD:")
labelPassword.grid(row=1, column=0, padx=10, pady=5)
entryPassword = tk.Entry(app)
entryPassword.grid(row=1, column=1, padx=10, pady=5)
# Add button
buttonAdd = tk.Button(app, text="Add", command=add)
buttonAdd.grid(row=2, column=0, padx=15, pady=8, sticky="we")
# Get button
buttonGet = tk.Button(app, text="Get", command=get)
buttonGet.grid(row=2, column=1, padx=15, pady=8, sticky="we")
# List Button
buttonList = tk.Button(app, text="List", command=getlist)
buttonList.grid(row=3, column=0, padx=15, pady=8, sticky="we")
# Delete button
buttonDelete = tk.Button(app, text="Delete", command=delete)
buttonDelete.grid(row=3, column=1, padx=15, pady=8, sticky="we")
app.mainloop()
output: