Skip to content

Commit a0e00d2

Browse files
Merge branch 'kishanrajput23:main' into Vishwajeetbamane
2 parents 54bb2a3 + 3ebe589 commit a0e00d2

26 files changed

+1417
-1
lines changed

1st python program

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from datetime import date
2+
3+
today = date.today()
4+
5+
# dd/mm/YY
6+
d1 = today.strftime("%d/%m/%Y")
7+
print("d1 =", d1)
8+
9+
# Textual month, day and year
10+
d2 = today.strftime("%B %d, %Y")
11+
print("d2 =", d2)
12+
13+
# mm/dd/y
14+
d3 = today.strftime("%m/%d/%y")
15+
print("d3 =", d3)
16+
17+
# Month abbreviation, day and year
18+
d4 = today.strftime("%b-%d-%Y")
19+
print("d4 =", d4)
20+
21+
22+
OUTPUT
23+
https://www.programiz.com/python-programming/online-compiler/

Audio Book/Discord_bot_python.py

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import discord
2+
from discord.ext import commands
3+
import wikipedia
4+
from stackapi import StackAPI
5+
6+
7+
client = discord.Client()
8+
@client.event
9+
async def on_ready():
10+
print("Bot is online")
11+
12+
13+
@client.event
14+
async def on_message(message):
15+
message.content.lower()
16+
if message.author == client.user:
17+
return
18+
19+
elif message.content.startswith("hello") or message.content.startswith("Hello"):
20+
await message.channel.send("Hello, I am Cheatbot, here to help you cheat!")
21+
22+
elif message.content.startswith("cheat ping"):
23+
await message.channel.send(f'{round(client.latency*1000)}ms')
24+
25+
elif message.content.startswith("cheat wiki"):
26+
try:
27+
term =(message.content.split())
28+
search=''
29+
link=''
30+
for k in term[2:]:
31+
search=search + k + ' '
32+
link=link + k + '_'
33+
result = wikipedia.summary(search, sentences = 3)
34+
embed = discord.Embed(title='Go to wikipedia',url="https://en.wikipedia.org/wiki"+link,description=result)
35+
await message.channel.send(embed=embed)
36+
except:
37+
await message.channel.send("could not find "+search+" on wikipedia")
38+
39+
elif message.content.startswith("cheat question"):
40+
no_of_options=4
41+
question=''
42+
question_list=message.content.split()
43+
if question_list[-1].isnumeric():
44+
no_of_options=int(question_list[-1])
45+
for k in question_list[2:len(question_list)-1]:
46+
question=question + k + ' '
47+
else:
48+
no_of_options=4
49+
for k in question_list[2:len(question_list)]:
50+
question=question + k + ' '
51+
print(no_of_options)
52+
print(question)
53+
await message.channel.send(question)
54+
for k in range(no_of_options):
55+
await message.channel.send(reactions[k])
56+
57+
58+
elif message.content.startswith("cheat help"):
59+
await message.channel.send("""Commands
60+
-------------------------------------------------------------------------------------------------------
61+
1 : cheat wiki something to search
62+
This command will search wiki and give a short description, along with a link to that page
63+
2 : cheat error some error
64+
This command will search for your error on stack overflow and give links to 3 answers
65+
------------------------------------------------------------------------------------------------------
66+
Examples
67+
-------------------------------------------------------------------------------------------------------
68+
cheat wiki data structures
69+
cheat error SIGSEV""")
70+
71+
elif message.content.startswith("cheat error"):
72+
message.content.lower()
73+
error_statement=''
74+
error_list =(message.content.split())
75+
flag=0
76+
if error_list[-1].isnumeric():
77+
no_of_links=int(error_list[-1])
78+
error_statement=''
79+
flag=1
80+
for k in term[2:len(error_list)-1]:
81+
error_statement=error_statement + k + ' '
82+
else:
83+
error_statement=''
84+
for k in error_list[2:len(error_list)]:
85+
error_statement=error_statement + k + ' '
86+
def solve_error(error: str, max_links: int = 3) -> [(str, str)]:
87+
SITE = StackAPI('stackoverflow')
88+
comments = SITE.fetch('search/advanced', sort = 'relevance', q = error)
89+
count = 0
90+
links = []
91+
92+
for i, ans in enumerate(comments['items']):
93+
if ans['is_answered']:
94+
count += 1
95+
if count > max_links:
96+
break
97+
links.append((ans['title'], ans['link']))
98+
99+
return links
100+
if flag==1:
101+
for link in solve_error(error_statement,no_of_links):
102+
embed = discord.Embed(title=link[0],url=link[1],description="For more clarification visit above links")
103+
await message.channel.send(embed=embed)
104+
if flag==0:
105+
for link in solve_error(error_statement):
106+
embed = discord.Embed(title=link[0],url=link[1],description="For more clarification visit above links")
107+
await message.channel.send(embed=embed)
108+
109+
client.run('NzI3ODA1MjMyNDM5ODg1ODI1.XvxPCQ.QoLEMQb52qvntGPqb1nDr54bjfs')

Audio Book/sudoku.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
board = [
2+
[7,8,0,4,0,0,1,2,0],
3+
[6,0,0,0,7,5,0,0,9],
4+
[0,0,0,6,0,1,0,7,8],
5+
[0,0,7,0,4,0,2,6,0],
6+
[0,0,1,0,5,0,9,3,0],
7+
[9,0,4,0,6,0,0,0,5],
8+
[0,7,0,3,0,0,0,1,2],
9+
[1,2,0,0,0,7,4,0,0],
10+
[0,4,9,2,0,6,0,0,7]
11+
]
12+
13+
14+
def solve(bo):
15+
find = find_empty(bo)
16+
if not find:
17+
return True
18+
else:
19+
row, col = find
20+
21+
for i in range(1,10):
22+
if valid(bo, i, (row, col)):
23+
bo[row][col] = i
24+
25+
if solve(bo):
26+
return True
27+
28+
bo[row][col] = 0
29+
30+
return False
31+
32+
33+
def valid(bo, num, pos):
34+
# Check row
35+
for i in range(len(bo[0])):
36+
if bo[pos[0]][i] == num and pos[1] != i:
37+
return False
38+
39+
# Check column
40+
for i in range(len(bo)):
41+
if bo[i][pos[1]] == num and pos[0] != i:
42+
return False
43+
44+
# Check box
45+
box_x = pos[1] // 3
46+
box_y = pos[0] // 3
47+
48+
for i in range(box_y*3, box_y*3 + 3):
49+
for j in range(box_x * 3, box_x*3 + 3):
50+
if bo[i][j] == num and (i,j) != pos:
51+
return False
52+
53+
return True
54+
55+
56+
def print_board(bo):
57+
for i in range(len(bo)):
58+
if i % 3 == 0 and i != 0:
59+
print("- - - - - - - - - - - - - ")
60+
61+
for j in range(len(bo[0])):
62+
if j % 3 == 0 and j != 0:
63+
print(" | ", end="")
64+
65+
if j == 8:
66+
print(bo[i][j])
67+
else:
68+
print(str(bo[i][j]) + " ", end="")
69+
70+
71+
def find_empty(bo):
72+
for i in range(len(bo)):
73+
for j in range(len(bo[0])):
74+
if bo[i][j] == 0:
75+
return (i, j) # row, col
76+
77+
return None
78+
79+
print_board(board)
80+
solve(board)
81+
print("___________________")
82+
print_board(board)

BMI.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Height=float(input("Enter your height in centimeters: "))
2+
Weight=float(input("Enter your Weight in Kg: "))
3+
Height = Height/100
4+
BMI=Weight/(Height*Height)
5+
print("your Body Mass Index is: ",BMI)
6+
if(BMI>0):
7+
if(BMI<=16):
8+
print("you are severely underweight")
9+
elif(BMI<=18.5):
10+
print("you are underweight")
11+
elif(BMI<=25):
12+
print("you are Healthy")
13+
elif(BMI<=30):
14+
print("you are overweight")
15+
else: print("you are severely overweight")
16+
else:("enter valid details")

Color game/Readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Color Game
2+
Enter the color of the words displayed below. And Keep in mind not to enter the word text itself and to move for next text press the enter button

Color game/app.py

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from tkinter import *
2+
import tkinter.font as font
3+
import random
4+
5+
colors=["Red", "Orange", "White", "Black", "Green", "Blue", "Brown", "Purple", "Cyan", "Yellow", "Pink", "Magenta"]
6+
timer=60
7+
score=0
8+
displayed_word_color=''
9+
10+
11+
# This function will be called when start button is clicked
12+
def startGame():
13+
global displayed_word_color
14+
15+
if timer==60:
16+
startCountDown()
17+
displayed_word_color=random.choice(colors).lower()
18+
display_words.config(text=random.choice(colors), fg=displayed_word_color)
19+
color_entry.bind('<Return>', displayNextWord)
20+
21+
# This function is to reset the game
22+
def resetGame():
23+
global timer, score, displayed_word_color
24+
timer=60
25+
score=0
26+
displayed_word_color=''
27+
game_score.config(text="Your Score : "+str(score))
28+
display_words.config(text='')
29+
time_left.config(text="Game Ends in : -")
30+
color_entry.delete(0, END)
31+
32+
# This function will start count down
33+
def startCountDown():
34+
global timer
35+
if timer>=0:
36+
time_left.config(text="Game Ends in : "+str(timer)+"s")
37+
timer-=1
38+
time_left.after(1000,startCountDown)
39+
if timer==-1:
40+
time_left.config(text="Game Over!!!")
41+
42+
43+
# This function to display random words
44+
def displayNextWord(event):
45+
global displayed_word_color
46+
global score
47+
if timer>0:
48+
if displayed_word_color==color_entry.get().lower():
49+
score+=1
50+
game_score.config(text="Your Score : "+str(score))
51+
color_entry.delete(0, END)
52+
displayed_word_color=random.choice(colors).lower()
53+
display_words.config(text=random.choice(colors), fg=displayed_word_color)
54+
55+
56+
root=Tk()
57+
root.title("Color Game")
58+
root.geometry("500x200")
59+
root.iconbitmap("./img/game-console.ico")
60+
61+
app_font=font.Font(family='Helvetica', size=12)
62+
63+
game_desp="Game Description: Enter the color of the words displayed below. \n And Keep in mind not to enter the " \
64+
"word text itself "
65+
myFont=font.Font(family='Helvetica')
66+
67+
game_description=Label(root, text=game_desp,font=app_font, fg="grey")
68+
game_description.pack()
69+
70+
game_score=Label(root, text="Your Score : "+str(score), font=(font.Font(size=16)), fg="green")
71+
game_score.pack()
72+
73+
display_words=Label(root,font=(font.Font(size=28)), pady=10)
74+
display_words.pack()
75+
76+
time_left=Label(root,text="Game Ends in : -", font=(font.Font(size=14)), fg="orange")
77+
time_left.pack()
78+
79+
color_entry=Entry(root, width=30)
80+
color_entry.pack(pady=10)
81+
82+
btn_frame=Frame(root, width=80, height=40, bg='red')
83+
btn_frame.pack(side=BOTTOM)
84+
85+
start_button=Button(btn_frame, text="Start", width=20, fg="black", bg="pink", bd=0, padx=20, pady=10,command=startGame)
86+
start_button.grid(row=0, column=0)
87+
88+
reset_button=Button(btn_frame, text="Reset",width=20, fg="black",bg="light blue", bd=0, padx=20, pady=10, command=resetGame)
89+
reset_button.grid(row=0, column=1)
90+
91+
root.geometry('600x300')
92+
root.mainloop()

0 commit comments

Comments
 (0)