diff --git a/challenges124_132/challenge-124_.py b/challenges124_132/challenge-124_.py new file mode 100644 index 0000000..7f4d20f --- /dev/null +++ b/challenges124_132/challenge-124_.py @@ -0,0 +1,29 @@ +from tkinter import * + +def click(): + name=textbox1.get() + message=str("Hello " + name) + textbox2["bg"]="yellow" + textbox2["fg"]="blue" + textbox2["text"]=message + +window=Tk() +window.geometry("500x200") + +label1=Label(text="Enter your name: ") +label1.place(x=30, y=20) + +textbox1=Entry(text="") +textbox1.place(x=150, y=20, width=200, height=25) +textbox1["justify"]="center" +textbox1.focus() + +button1=Button(text="Press me", command=click) +button1.place(x=30,y=50, width=120, height=25) + +textbox2=Message(text="") +textbox2.place(x=150, y=50, width=200, height=25) +textbox2["bg"]="white" +textbox2["fg"]="black" + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-125_.py b/challenges124_132/challenge-125_.py new file mode 100644 index 0000000..5b4cd87 --- /dev/null +++ b/challenges124_132/challenge-125_.py @@ -0,0 +1,18 @@ +from tkinter import * +import random + +def click(): + num=random.randint(1,6) + answer["text"]=num + +window=Tk() +window.title("Roll a dice") +window.geometry("100x120") + +button1=Button(text="Roll", command=click) +button1.place(x=30, y=30, width=50, height=25) + +answer=Message(text="") +answer.place(x=40, y=70, width=30, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-126_.py b/challenges124_132/challenge-126_.py new file mode 100644 index 0000000..bb64c88 --- /dev/null +++ b/challenges124_132/challenge-126_.py @@ -0,0 +1,46 @@ +from tkinter import * + +def add_on(): + num=enter_txt.get() + num=int(num) + answer=output_txt["text"] + answer=int(answer) + total=num+answer + output_txt["text"]=total + +def reset(): + total=0 + output_txt["text"]=0 + enter_txt.delete(0,END) + enter_txt.focus() + +total=0 +num=0 + +window=Tk() +window.title("Adding Together") +window.geometry("450x100") + +enter_lbl=Label(text="Enter a number: ") +enter_lbl.place(x=50, y=20, width=100, height=25) + +enter_txt=Entry(text=0) +enter_txt.place(x=150, y=20, width=100, height=25) +enter_txt["justify"]="center" +enter_txt.focus() + +add_btn=Button(text="Add", command=add_on) +add_btn.place(x=300, y=20, width=50, height=25) + +output_lbl=Label(text="Answer= ") +output_lbl.place(x=50, y=50, width=100, height=25) + +output_txt=Message(text=0) +output_txt.place(x=150, y=50, width=100, height=25) +output_txt["bg"]="white" +output_txt["relief"]="sunken" + +clear_btn=Button(text="Clear", command=reset) +clear_btn.place(x=300, y=50, width=50, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-127_.py b/challenges124_132/challenge-127_.py new file mode 100644 index 0000000..8b7767f --- /dev/null +++ b/challenges124_132/challenge-127_.py @@ -0,0 +1,33 @@ +from tkinter import * + +def add_name(): + name=name_box.get() + name_list.insert(END,name) + name_box.delete(0,END) + name_box.focus() + +def clear_list(): + name_list.delete(0,END) + name_box.focus() + +window=Tk() +window.title("Names list") +window.geometry("400x200") + +label1=Label(text="Enter a name: ") +label1.place(x=20, y=20, width=100, height=25) + +name_box=Entry(text=0) +name_box.place(x=120, y=20, width=100, height=25) +name_box.focus() + +button1=Button(text="Add to list", command=add_name) +button1.place(x=250, y=20, width=100, height=25) + +name_list=Listbox() +name_list.place(x=120, y=50, width=100, height=100) + +button2=Button(text="Clear list", command=clear_list) +button2.place(x=250, y=50, width=100, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-128_.py b/challenges124_132/challenge-128_.py new file mode 100644 index 0000000..4fbc2cc --- /dev/null +++ b/challenges124_132/challenge-128_.py @@ -0,0 +1,41 @@ +from tkinter import * + +def convert1(): + mile=textbox2.get() + mile=int(mile) + message=mile/0.6214 + textbox1.delete(0,END) + textbox1.insert(END, message) + textbox1.insert(END, "km") + +def convert2(): + km=textbox1.get() + km=int(km) + message=km*0.6214 + textbox2.delete(0,END) + textbox2.insert(END, message) + textbox2.insert(END, "miles") + +window=Tk() +window.title("Distance") +window.geometry("260x200") + +label1=Label(text="Enter the value you want to convert: ") +label1.place(x=30, y=20) + +textbox1=Entry(text="") +textbox1.place(x=30, y=50, width=200, height=25) +textbox1["justify"]="center" +textbox1.focus() + +convert1=Button(text="Convert miles to km", command=convert1 ) +convert1.place(x=30, y=80, width=200, height=25) + +convert2=Button(text="Convert km to mile", command=convert2 ) +convert2.place(x=30, y=110, width=200, height=25) + +textbox2=Entry(text="") +textbox2.place(x=30, y=140, width=200, height=25) +textbox2["justify"]="center" + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-129_.py b/challenges124_132/challenge-129_.py new file mode 100644 index 0000000..d0974c8 --- /dev/null +++ b/challenges124_132/challenge-129_.py @@ -0,0 +1,37 @@ +from tkinter import * + +def add_number(): + num=num_box.get() + if num.isdigit(): + num_list.insert(END,num) + num_box.delete(0,END) + num_box.focus() + else: + num_box.delete(0,END) + num_box.focus() + +def clear_list(): + num_list.delete(0,END) + num_box.focus() + +window=Tk() +window.title("Number list") +window.geometry("400x200") + +label1=Label(text="Enter a number: ") +label1.place(x=20, y=20, width=100, height=25) + +num_box=Entry(text=0) +num_box.place(x=120, y=20, width=100, height=25) +num_box.focus() + +num_list=Listbox() +num_list.place(x=120, y=50, width=100, height=100) + +button1=Button(text="Add to list", command=add_number) +button1.place(x=250, y=20, width=100, height=25) + +button2=Button(text="Clear list", command=clear_list) +button2.place(x=250, y=50, width=100, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-130_.py b/challenges124_132/challenge-130_.py new file mode 100644 index 0000000..3b0acde --- /dev/null +++ b/challenges124_132/challenge-130_.py @@ -0,0 +1,51 @@ +from tkinter import * +import csv + +def add_number(): + num=num_box.get() + if num.isdigit(): + num_list.insert(END,num) + num_box.delete(0,END) + num_box.focus() + else: + num_box.delete(0,END) + num_box.focus() + +def clear_list(): + num_list.delete(0,END) + num_box.focus() + +def save_list(): + file=open("numbers.csv","w") + tmp_list=num_list.get(0,END) + item=0 + for x in tmp_list: + newrecord=tmp_list[item]+"\n" + file.write(str(newrecord)) + item=item+1 + file.close() + +window=Tk() +window.title("Number list") +window.geometry("400x200") + +label1=Label(text="Enter a number: ") +label1.place(x=20, y=20, width=100, height=25) + +num_box=Entry(text=0) +num_box.place(x=120, y=20, width=100, height=25) +num_box.focus() + +num_list=Listbox() +num_list.place(x=120, y=50, width=100, height=100) + +button1=Button(text="Add to list", command=add_number) +button1.place(x=250, y=20, width=100, height=25) + +button2=Button(text="Clear list", command=clear_list) +button2.place(x=250, y=50, width=100, height=25) + +button3=Button(text="Save list", command=save_list) +button3.place(x=250, y=80, width=100, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-131_.py b/challenges124_132/challenge-131_.py new file mode 100644 index 0000000..275441e --- /dev/null +++ b/challenges124_132/challenge-131_.py @@ -0,0 +1,44 @@ +from tkinter import * +import csv + +def create_new(): + file=open("ages.csv","w") + file.close() + +def save_list(): + file=open("ages.csv","a") + name=name_box.get() + age=age_box.get() + newrecord=name+","+age+"\n" + file.write(str(newrecord)) + file.close() + name_box.delete(0,END) + age_box.delete(0,END) + name_box.focus() + +window=Tk() +window.title("People List") +window.geometry("400x100") + +label1=Label(text="Enter a name: ") +label1.place(x=20, y=20, width=100, height=25) + +name_box=Entry(text="") +name_box.place(x=120, y=20, width=100, height=25) +name_box["justify"]="left" +name_box.focus() + +label2=Label(text="Enter their age: ") +label2.place(x=20, y=50, width=100, height=25) + +age_box=Entry(text="") +age_box.place(x=120, y=50, width=100, height=25) +age_box["justify"]="left" + +button1=Button(text="Create a new file", command=create_new) +button1.place(x=250, y=20, width=100, height=25) + +button2=Button(text="Add to file", command=save_list) +button2.place(x=250, y=50, width=100, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/challenge-132_.py b/challenges124_132/challenge-132_.py new file mode 100644 index 0000000..b845510 --- /dev/null +++ b/challenges124_132/challenge-132_.py @@ -0,0 +1,58 @@ +from tkinter import * +import csv + +def save_list(): + file=open("ages.csv","a") + name=name_box.get() + age=age_box.get() + newrecord=name+","+age+"\n" + file.write(str(newrecord)) + file.close() + name_box.delete(0,END) + age_box.delete(0,END) + name_box.focus() + +def read_list(): + name_list.delete(0,END) + file=list(csv.reader(open("ages.csv"))) + tmp=[] + for row in file: + tmp.append(row) + x=0 + for i in tmp: + data=tmp[x] + name_list.insert(END,data) + x=x+1 + +window=Tk() +window.title("People List") +window.geometry("400x200") + +label1=Label(text="Enter a name: ") +label1.place(x=20, y=20, width=100, height=25) + +name_box=Entry(text="") +name_box.place(x=120, y=20, width=100, height=25) +name_box["justify"]="left" +name_box.focus() + +label2=Label(text="Enter their age: ") +label2.place(x=20, y=50, width=100, height=25) + +age_box=Entry(text="") +age_box.place(x=120, y=50, width=100, height=25) +age_box["justify"]="left" + +button1=Button(text="Add to file", command=save_list) +button1.place(x=250, y=20, width=100, height=25) + +button2=Button(text="Read list", command=read_list) +button2.place(x=250, y=50, width=100, height=25) + +label3=Label(text="Saved names: ") +label3.place(x=20, y=80, width=100, height=25) + +name_list=Listbox() +name_list.place(x=120, y=80, width=230, height=100) + +window.mainloop() \ No newline at end of file diff --git a/challenges124_132/readme.md b/challenges124_132/readme.md new file mode 100644 index 0000000..62e6010 --- /dev/null +++ b/challenges124_132/readme.md @@ -0,0 +1 @@ +files added by chemineer diff --git a/challenges133_138/1.png b/challenges133_138/1.png new file mode 100644 index 0000000..8c7f7c2 Binary files /dev/null and b/challenges133_138/1.png differ diff --git a/challenges133_138/challenge-133_.py b/challenges133_138/challenge-133_.py new file mode 100644 index 0000000..1217eae --- /dev/null +++ b/challenges133_138/challenge-133_.py @@ -0,0 +1,37 @@ +from tkinter import * + +def click(): + name=textbox1.get() + message=str("Hello "+name) + textbox2["text"]=message + +window=Tk() +window.title("Names") +window.geometry("450x350") +#window.wm_iconbitmap("stripes.ico") +window.configure(background="black") + +logo=PhotoImage(file="1.png") +logoimage=Label(image=logo) +logoimage.place(x=100, y=20, width=200, height=150) + +label1=Label(text="Enter your name: ") +label1.place(x=30, y=200) +label1["bg"]="black" +label1["fg"]="white" + +textbox1=Entry(text="") +textbox1.place(x=150, y=200, width=200, height=25) +textbox1["justify"]="center" +textbox1.focus() + +button1=Button(text="Press me", command=click) +button1.place(x=30, y=250, width=120, height=25) +button1["bg"]="yellow" + +textbox2=Message(text="") +textbox2.place(x=150, y=250, width=200, height=25) +textbox2["bg"]="white" +textbox2["fg"]="black" + +window.mainloop() \ No newline at end of file diff --git a/challenges133_138/challenge-134_.py b/challenges133_138/challenge-134_.py new file mode 100644 index 0000000..bba2699 --- /dev/null +++ b/challenges133_138/challenge-134_.py @@ -0,0 +1,62 @@ +from tkinter import * +import random + +def checkans(): + theirans=int(ansbox.get()) + num1=int(num1box["text"]) + num2=int(num2box["text"]) + ans=num1+num2 + if theirans==ans: + img=PhotoImage(file="correct.png") + imgbx.image=img + else: + img=PhotoImage(file="wrong.pn53g") + imgbx.image=img + imgbx["image"]=img + imgbx.update() + +def nextquestion(): + ansbox.delete(0,END) + num1=random.randint(10,50) + num1box["text"]=num1 + num2=random.randint(10,50) + num2box["text"]=num2 + img=PhotoImage(file="") + imgbx.image=img + imgbx["image"]=img + imgbx.update() + + +window=Tk() +window.title("Addition") +window.geometry("250x300") + +num1box=Label(text="0") +num1box.place(x=50, y=30, width=25, height=25) +addsymbl=Message(text="+") +addsymbl.place(x=75, y=30, width=25, height=25) + +num2box=Label(text="0") +num2box.place(x=100, y=30, width=25, height=25) +eqlsymbl=Message(text="=") +eqlsymbl.place(x=125, y=30, width=25, height=25) + +ansbox=Entry(text="") +ansbox.place(x=150, y=30, width=25, height=25) +ansbox["justify"]="center" +ansbox.focus() + +checkbtn=Button(text="Check", command=checkans) +checkbtn.place(x=50, y=60, width=75, height=25) + +nextbtn=Button(text="Next", command=nextquestion) +nextbtn.place(x=130, y=60, width=75, height=25) + +img=PhotoImage(file="") +imgbx=Label(image=img) +imgbx.image=img +imgbx.place(x=25, y=100, width=200, height=150) + +nextquestion() + +window.mainloop() \ No newline at end of file diff --git a/challenges133_138/challenge-135_.py b/challenges133_138/challenge-135_.py new file mode 100644 index 0000000..548f3b1 --- /dev/null +++ b/challenges133_138/challenge-135_.py @@ -0,0 +1,20 @@ +from tkinter import * + +def clicked(): + sel=selectcolour.get() + window.configure(background=sel) + +window=Tk() +window.title("background") +window.geometry("200x200") + +selectcolour=StringVar(window) +selectcolour.set("Grey") + +colourlist=OptionMenu(window,selectcolour, "Grey", "Red", "Blue", "Green", "Yellow") +colourlist.place(x=50,y=30) + +clickme=Button(text="Click me", command=clicked) +clickme.place(x=50, y=150, width=60, height=30) + +window.mainloop() \ No newline at end of file diff --git a/challenges133_138/challenge-136_.py b/challenges133_138/challenge-136_.py new file mode 100644 index 0000000..773865e --- /dev/null +++ b/challenges133_138/challenge-136_.py @@ -0,0 +1,38 @@ +from tkinter import * + +def add_to_list(): + name=namebox.get() + namebox.delete(0,END) + genderselection = gender.get() + gender.set("M/F") + newdata = name + "," + genderselection + "\n" + name_list.insert(END,newdata) + namebox.focus() + +window=Tk() +window.title("People list") +window.geometry("400x400") + +namelbl=Label(text="Enter their name") +namelbl.place(x=50, y=50, width=100, height=25) + +namebox=Entry(text="") +namebox.place(x=150, y=50, width=150, height=25) +namebox.focus() + +genderlbl=Label(text="Select gender") +genderlbl.place(x=50, y=100, width=100, height=25) + +gender=StringVar(window) +gender.set("M/F") + +gendermenu=OptionMenu(window,gender, "M", "F") +gendermenu.place(x=150,y=100) + +name_list=Listbox() +name_list.place(x=150, y=150, width=150, height=100) + +addbtn=Button(text="Add to list", command=add_to_list) +addbtn.place(x=50, y=300, width=100, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges133_138/challenge-137_.py b/challenges133_138/challenge-137_.py new file mode 100644 index 0000000..39afa8b --- /dev/null +++ b/challenges133_138/challenge-137_.py @@ -0,0 +1,48 @@ +from tkinter import * + +def add_to_list(): + name=namebox.get() + namebox.delete(0,END) + genderselection = gender.get() + gender.set("M/F") + newdata = name + "," + genderselection + "\n" + name_list.insert(END,newdata) + namebox.focus() + file=open("names.txt","a") + file.write(newdata) + file.close() + +def print_list(): + file=open("names.txt","r") + print(file.read()) + +window=Tk() +window.title("People list") +window.geometry("400x400") + +namelbl=Label(text="Enter their name") +namelbl.place(x=50, y=50, width=100, height=25) + +namebox=Entry(text="") +namebox.place(x=150, y=50, width=150, height=25) +namebox.focus() + +genderlbl=Label(text="Select gender") +genderlbl.place(x=50, y=100, width=100, height=25) + +gender=StringVar(window) +gender.set("M/F") + +gendermenu=OptionMenu(window,gender, "M", "F") +gendermenu.place(x=150,y=100) + +name_list=Listbox() +name_list.place(x=150, y=150, width=150, height=100) + +addbtn=Button(text="Add to list", command=add_to_list) +addbtn.place(x=50, y=300, width=100, height=25) + +printlst=Button(text="Print list", command=print_list) +printlst.place(x=175, y=300, width=100, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges133_138/challenge-138_.py b/challenges133_138/challenge-138_.py new file mode 100644 index 0000000..6542e1f --- /dev/null +++ b/challenges133_138/challenge-138_.py @@ -0,0 +1,33 @@ +#Sometimes, it doesn't work with certain error message on Jupyter notebook. +#In case of error, restart IDE and that will do. + +from tkinter import * + +def clicked(): + num=selection.get() + artref=num+".png" + photo=PhotoImage(file=artref) + photobox.image=photo + photobox["image"]=photo + photobox.update() + +window=Tk() +window.title("Art") +window.geometry("400x350") + +art=PhotoImage(file="1.png") +photobox=Label(window, image=art) +photobox.image=art +photobox.place(x=100, y=20, width=200, height=150) + +label=Label(text="Select art number: ") +label.place(x=50, y=200, width=100, height=25) + +selection=Entry(text="") +selection.place(x=200, y=200, width=100, height=25) +selection.focus() + +clickme=Button(text="See art", command=clicked) +clickme.place(x=150, y=250, width=100, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges133_138/readme.md b/challenges133_138/readme.md new file mode 100644 index 0000000..62e6010 --- /dev/null +++ b/challenges133_138/readme.md @@ -0,0 +1 @@ +files added by chemineer diff --git a/challenges139-145/BookInfo.db b/challenges139-145/BookInfo.db new file mode 100644 index 0000000..f25aa2d Binary files /dev/null and b/challenges139-145/BookInfo.db differ diff --git a/challenges139-145/challenge-143_.py b/challenges139-145/challenge-143_.py new file mode 100644 index 0000000..e22c46e --- /dev/null +++ b/challenges139-145/challenge-143_.py @@ -0,0 +1,15 @@ +import sqlite3 + +with sqlite3.connect("BookInfo.db") as db: + cursor=db.cursor() + +selectionyear=int(input("Enter a year: ")) +print() + +cursor.execute("""SELECT Books.Title, Books.DatePublished, Books.Author +FROM Books WHERE DatePublished >? ORDER BY DatePublished""", [selectionyear]) + +for x in cursor.fetchall(): + print(x) + +db.close() \ No newline at end of file diff --git a/challenges139-145/challenge-144_.py b/challenges139-145/challenge-144_.py new file mode 100644 index 0000000..69c0043 --- /dev/null +++ b/challenges139-145/challenge-144_.py @@ -0,0 +1,23 @@ +import sqlite3 + +file = open("Booklist.txt","w") + +with sqlite3.connect("BookInfo.db") as db: + cursor=db.cursor() + +cursor.execute("SELECT Name from Authors") +for x in cursor.fetchall(): + print(x) + +print() +selectauthor=input("Enter an author's name: ") +print() + +cursor.execute("SELECT * from Books WHERE Author=?", [selectauthor]) +for x in cursor.fetchall(): + newrecord=str(x[0])+" - "+x[1]+" - "+x[2]+" - "+str(x[3])+"\n" + file.write(newrecord) + +file.close() + +db.close() \ No newline at end of file diff --git a/challenges139-145/challenge-145_.py b/challenges139-145/challenge-145_.py new file mode 100644 index 0000000..fab2033 --- /dev/null +++ b/challenges139-145/challenge-145_.py @@ -0,0 +1,46 @@ +import sqlite3 +from tkinter import * + +def addtolist(): + newname=sname.get + newgrade=sgrade.get + cursor.execute("INSERT INTO Scores (name,score) VALUES (?,?)", (newname,newgrade)) + db.commit() + sname.delete(0,END) + sgrade.delete(0,END) + sname.focus() + +def clearlist(): + sname.delete(0,END) + sgrade.delete(0,END) + sname.focus() + +with sqlite3.connect("TestScore.db") as db: + cursor=db.cursor() + +cursor.execute("""CREATE TABLE IF NOT EXISTS Scores( + id integer RIMAY KEY, name text, score integer);""") + +window=Tk() +window.title("TestScores") +window.geometry("450x200") + +label1=Label(text="Enter student's name: ") +label1.place(x=30, y=35) +sname=Entry(text="") +sname.place(x=150, y=35, width=200, height=25) +sname.focus() + +label2=Label(text="Enter student's grade: ") +label2.place(x=30, y=80) +sgrade=Entry(text="") +sgrade.place(x=150, y=80, width=200, height=25) +sgrade.focus() + +addbtn=Button(text="Add", command=addtolist) +addbtn.place(x=150, y=120, width=75, height=25) +clearbtn=Button(text="Clear", command=clearlist) +clearbtn.place(x=250, y=120, width=75, height=25) + +window.mainloop() +db.close \ No newline at end of file diff --git a/challenges146_150/challenge-146_.py b/challenges146_150/challenge-146_.py new file mode 100644 index 0000000..4152396 --- /dev/null +++ b/challenges146_150/challenge-146_.py @@ -0,0 +1,57 @@ +alphabet=["a", "b", "c", "d", "e", "f", "g", "h", "i", +"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", +"u", "v", "w", "x", "y", "z", " "] + +def get_data(): + word=input("Enter your message: ") + word=word.lower() + num=int(input("Enter a number (1-26): ")) + while num>26 or num==0: + num=int(input("Out of range, Please enter a number (1-26): ")) + data=(word,num) + return(data) + +def make_code(word,num): + new_word="" + for x in word: + y=alphabet.index(x) + y=y+num + if y>26: + y=y-27 + char=alphabet[y] + new_word=new_word +char + print(new_word) + print() + +def decode(word,num): + new_word="" + for x in word: + y=alphabet.index(x) + y=y-num + if y<0: + y=y+27 + char=alphabet[y] + new_word=new_word +char + print(new_word) + print() + +def main(): + again=True + while again==True: + print("1) Make a code") + print("2) Decode a message") + print("3) Quit") + print() + selection=int(input("Enter your selection: ")) + if selection==1: + (word,num)=get_data() + make_code(word,num) + elif selection==2: + (word,num)=get_data() + decode(word,num) + elif selection==3: + again=False + else: + print("Incorrect selection") + +main() diff --git a/challenges146_150/challenge-147_.py b/challenges146_150/challenge-147_.py new file mode 100644 index 0000000..8d787ce --- /dev/null +++ b/challenges146_150/challenge-147_.py @@ -0,0 +1,92 @@ +import random + +def select_col(): + colours=["r", "b", "o", "y", "p", "g", "w"] + c1=random.choice(colours) + c2=random.choice(colours) + c3=random.choice(colours) + c4=random.choice(colours) + data=(c1, c2, c3, c4) + return data + +def tryit(c1, c2, c3, c4): + print("The colours are: (r)ed, (b)lue, (o)range, (y)ellow, (p)ink, (g)reen, (w)hite") + try_again=True + while try_again==True: + u1=input("Enter your choice for place 1: ") + u1=u1.lower() + if u1 !="r" and u1 !="b" and u1 !="o" and u1 !="y" and u1 !="p" and u1 !="g" and u1 !="w": + print("Incorrect selection") + else: + try_again=False + + try_again=True + while try_again==True: + u2=input("Enter your choice for place 2: ") + u2=u2.lower() + if u2 !="r" and u2 !="b" and u2 !="o" and u2 !="y" and u2 !="p" and u2 !="g" and u2 !="w": + print("Incorrect selection") + else: + try_again=False + + try_again=True + while try_again==True: + u3=input("Enter your choice for place 3: ") + u3=u3.lower() + if u3 !="r" and u3 !="b" and u3 !="o" and u3 !="y" and u3 !="p" and u3 !="g" and u3 !="w": + print("Incorrect selection") + else: + try_again=False + + try_again=True + while try_again==True: + u4=input("Enter your choice for place 4: ") + u4=u4.lower() + if u4 !="r" and u4 !="b" and u4 !="o" and u4 !="y" and u4 !="p" and u4 !="g" and u4 !="w": + print("Incorrect selection") + else: + try_again=False + + correct=0 + wrong_place=0 + + if c1==u1: + correct=correct+1 + elif c1==u2 or c1==u3 or c1==u4: + wrong_place=wrong_place+1 + + if c2==u2: + correct=correct+1 + elif c2==u1 or c2==u3 or c2==u4: + wrong_place=wrong_place+1 + + if c3==u3: + correct=correct+1 + elif c3==u1 or c3==u2 or c3==u4: + wrong_place=wrong_place+1 + + if c4==u4: + correct=correct+1 + elif c4==u1 or c4==u2 or c4==u3: + wrong_place=wrong_place+1 + + print("Correct colour in the correct place: ", correct) + print("Correct colour but in the wrong place: ", wrong_place) + print() + + data2=(correct, wrong_place) + return data2 + +def main(): + (c1, c2, c3, c4) = select_col() + score = 0 + play = True + while play == True: + (correct, wrong_place) = tryit(c1, c2, c3, c4) + score=score+1 + if correct==4: + play=False + print("You win!") + print("You took", score, "guesses") + +main() \ No newline at end of file diff --git a/challenges146_150/challenge-148_.py b/challenges146_150/challenge-148_.py new file mode 100644 index 0000000..593dde4 --- /dev/null +++ b/challenges146_150/challenge-148_.py @@ -0,0 +1,144 @@ +import csv + +def get_data(): + file=list(csv.reader(open("passwords.csv"))) + tmp=[] + for x in file: + tmp.append(x) + return tmp + +def create_userID(tmp): + name_again=True + while name_again==True: + userID=input("Enter a new user ID: ") + userID.lower() + inlist=False + row=0 + for y in tmp: + if userID in tmp[row][0]: + print(userID, "has already been allocated") + inlist=True + row=row+1 + if inlist==False: + name_again=False + return userID + +def create_password(): + sclist=["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "?"] + nclist=["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + tryagain=True + while tryagain==True: + score=0 + uc=False + lc=False + sc=False + nc=False + password=input("Enter Password: ") + password2=input("Enter password again: ") + length=len(password) + if length>=8: + score=score+1 + for x in password: + if x.islower(): + lc=True + if x.isupper(): + uc=True + if x in sclist: + sc=True + if x in nclist: + ns=True + + if sc==True: + score=score+1 + if lc==True: + score=score+1 + if uc==True: + score=score+1 + if nc==True: + score=score+1 + + if score==1 or score==2: + print("This is a weak password. Try again.") + + if score==3 or score==4: + print("This password could be improved. ") + again=input("Do you want to try for a stronger password? (y/n) ") + again.lower() + if again=="n": + tryagain=False + + if password != password2: + print("Password do not match. File not saved") + main() + else: + return password + +def find_userID(tmp): + ask_name_again=True + userID="" + while ask_name_again == True: + searchID=input("Enter the user ID you are looking for ") + searchID.lower() + inlist=False + row=0 + for y in tmp: + if searchID in tmp[row][0]: + inlist=True + row=row+1 + if inlist==True: + userID=searchID + ask_name_again=False + else: + print(searchID, "is NOT in the list") + return userID + +def change_password(userID,tmp): + if userID!="": + password=create_password() + ID=userID.index(userID) + tmp(ID)[1]=password + file=open("passwords.csv", "w") + x=0 + for row in tmp: + newrecord=tmp[x][0] + "," +tmp[x][1] + "\n" + file.write(newrecord) + x=x+1 + file.close() + +def display_all_userID(): + tmp=get_data() + x=0 + for row in tmp: + print(tmp[x][0]) + x=x+1 + +def main(): + tmp=get_data() + go_again=True + while go_again==True: + print() + print("1) Create a new User ID") + print("2) Change a password") + print("3) Display all User IDs") + print("4) Quit") + print() + + selection=int(input("Enter Selection: ")) + if selection==1: + userID=create_userID(tmp) + password=create_password() + file=open("Passwords.csv","a") + newrecord=userID+","+password+"\n" + file.write(str(newrecord)) + file.close() + elif selection==2: + userID=find_userID(tmp) + change_password(userID,tmp) + elif selection==3: + display_all_userID() + elif selection==4: + go_again=False + else: + print("Incorrect selection") + +main() \ No newline at end of file diff --git a/challenges146_150/challenge-149_.py b/challenges146_150/challenge-149_.py new file mode 100644 index 0000000..0653a10 --- /dev/null +++ b/challenges146_150/challenge-149_.py @@ -0,0 +1,38 @@ +from tkinter import * + +def show_table(): + num=int(num_box.get()) + value=1 + for i in range (1,13): + answer=i*num + num_list.insert(END,(i, "x", num, "=", answer)) + value=value+1 + num_box.delete(0,END) + num_box.focus() + +def clear_list(): + num_box.delete(0,END) + num_list.delete(0,END) + num_box.focus() + +window=Tk() +window.title=("Times Table") +window.geometry("400x280") + +label1=Label(text="Enter a number: ") +label1.place(x=20, y=20, width=100, height=25) + +num_box=Entry(text=0) +num_box.place(x=120, y=20, width=100, height=25) +num_box.focus() + +button1=Button(text="View Times Table", command=show_table) +button1.place(x=250, y=20, width=120, height=25) + +num_list=Listbox() +num_list.place(x=120, y=50, width=100, height=200) + +button2=Button(text="Clear", command=clear_list) +button2.place(x=250, y=50, width=120, height=25) + +window.mainloop() \ No newline at end of file diff --git a/challenges146_150/challenge-150_.py b/challenges146_150/challenge-150_.py new file mode 100644 index 0000000..3804ba0 --- /dev/null +++ b/challenges146_150/challenge-150_.py @@ -0,0 +1,230 @@ +import sqlite3 +from tkinter import * + +with sqlite3.connect("Art.db") as db: + cursor=db.cursor() + +cursor.execute("""CREATE TABLE IF NOT EXISTS Artists(artistid integer PRIMARY KEY, name text, address text, town text, county text, postcode text); +""") + +cursor.execute("""CREATE TABLE IF NOT EXISTS Art(pieceid integer PRIMARY KEY, artistid integer, title text, medium text, price integer); +""") + +def addartist(): + newname=artistname.get() + newaddress=artistadd.get() + newtown=artisttown.get() + newcounty=artistcounty.get() + newpostcode=artistpostcode.get() + cursor.execute("""INSERT INTO Artists(name, address, town, county, postcode) + VALUES (?,?,?,?,?)""",(newname, newaddress, newtown, newcounty, newpostcode)) + db.commit() + artistname.delete(0,END) + artistadd.delete(0,END) + artisttown.delete(0,END) + artistcounty.delete(0,END) + artistpostcode.delete(0,END) + artistname.focus() + +def clearartist(): + artistname.delete(0,END) + artistadd.delete(0,END) + artisttown.delete(0,END) + artistcounty.delete(0,END) + artistpostcode.delete(0,END) + artistname.focus() + +def addart(): + newartname=artname.get() + newtitle=arttitle.get() + newmedium=medium.get() + newprice=artprice.get() + cursor.execute("""INSERT INTO Art(artistid, title, medium, price) + VALUES (?,?,?,?)""",(newartname, newtitle, newmedium, newprice)) + db.commit() + artname.delete(0,END) + arttitle.delete(0,END) + medium.set("") + artprice.delete(0,END) + artistname.focus() + +def clearart(): + artname.delete(0,END) + arttitle.delete(0,END) + medium.set("") + artprice.delete(0,END) + artistname.focus() + +def clearwindow(): + outputwindow.delete(0,END) + +def viewartists(): + cursor.execute("SELECT * FROM Artists") + for x in cursor.fetchall(): + newrecord=str(x[0])+","+str(x[1])+","+str(x[2])+","+str(x[3])+","+str(x[4])+","+x[5]+"\n" + outputwindow.insert(END,newrecord) + +def viewart(): + cursor.execute("SELECT * FROM Art") + for x in cursor.fetchall(): + newrecord=str(x[0])+","+str(x[1])+","+str(x[2])+","+str(x[3])+","+str(x[4])+"\n" + outputwindow.insert(END,newrecord) + +def searchartistoutput(): + selectedartist=searchartist.get() + cursor.execute("SELECT name FROM Artists WHERE artistid=?",[selectedartist]) + for x in cursor.fetchall(): + outputwindow.insert(END,x) + cursor.execute("SELECT * FROM Art WHERE artistid=?",[selectedartist]) + for x in cursor.fetchall(): + newrecord=str(x[0])+","+str(x[1])+","+str(x[2])+","+str(x[3])+","+str(x[4])+"\n" + outputwindow.insert(END,newrecord) + searchartist.delete(0,END) + searchartist.focus() + +def searchmediumoutput(): + selectedmedium=medium2.get() + cursor.execute("SELECT Art.pieceid, Artists.name, Art.title, Art.medium, Art.price FROM Artists, Art WHERE Artists.artistid=Art.artistid AND Art.medium=?",[selectedmedium]) + for x in cursor.fetchall(): + newrecord=str(x[0])+","+str(x[1])+","+str(x[2])+","+str(x[3])+","+str(x[4])+"\n" + outputwindow.insert(END,newrecord) + medium2.set("") + +def searchbyprice(): + minprice=selectmin.get() + maxprice=selectmax.get() + cursor.execute("SELECT Art.pieceid, Artists.name, Art.title, Art.medium, Art.price FROM Artists, Art WHERE Artists.artistid=Art.artistid AND Art.price>=? AND Art.price<=?",[minprice,maxprice]) + for x in cursor.fetchall(): + newrecord=str(x[0])+","+str(x[1])+","+str(x[2])+","+str(x[3])+","+str(x[4])+"\n" + outputwindow.insert(END,newrecord) + selectmin.delete(0,END) + selectmax.delete(0,END) + selectmin.focus() + +def sold(): + file=open("SoldArt.txt","a") + selectedpiece=soldpiece.get() + cursor.execute("SELECT * FROM Art WHERE pieceid=?",[selectedpiece]) + for x in cursor.fetchall(): + newrecord=str(x[0])+","+str(x[1])+","+str(x[2])+","+str(x[3])+","+str(x[4])+"\n" + file.write(newrecord) + file.close() + cursor.execute("DELETE FROM Art WHERE pieceid=?",[selectedpiece]) + db.commit() + +window=Tk() +window.title("Art") +window.geometry("1220x600") + +title1=Label(text="Enter new details: ") +title1.place(x=10, y=10, width=100, height=25) + +artistnamelbl=Label(text="Name: ") +artistnamelbl.place(x=30, y=40, width=80, height=25) +artistname=Entry(text="") +artistname.place(x=110, y=40, width=200, height=25) +artistname.focus() + +artistaddlbl=Label(text="Address: ") +artistaddlbl.place(x=310, y=40, width=80, height=25) +artistadd=Entry(text="") +artistadd.place(x=390, y=40, width=200, height=25) + +artisttownlbl=Label(text="Town: ") +artisttownlbl.place(x=590, y=40, width=80, height=25) +artisttown=Entry(text="") +artisttown.place(x=670, y=40, width=100, height=25) + +artistcountylbl=Label(text="County: ") +artistcountylbl.place(x=770, y=40, width=80, height=25) +artistcounty=Entry(text="") +artistcounty.place(x=850, y=40, width=100, height=25) + +artistpostcodelbl=Label(text="Postcode: ") +artistpostcodelbl.place(x=950, y=40, width=80, height=25) +artistpostcode=Entry(text="") +artistpostcode.place(x=1030, y=40, width=100, height=25) + +addbtn=Button(text="Add Artist", command=addartist) +addbtn.place(x=110, y=80, width=130, height=25) + +clearbtn=Button(text="Clear Artist", command=clearartist) +clearbtn.place(x=250, y=80, width=130, height=25) + +artnamelbl=Label(text="Artist ID: ") +artnamelbl.place(x=30, y=120, width=80, height=25) +artname=Entry(text="") +artname.place(x=110, y=120, width=50, height=25) + +arttitlelbl=Label(text="Title: ") +arttitlelbl.place(x=200, y=120, width=80, height=25) +arttitle=Entry(text="") +arttitle.place(x=280, y=120, width=280, height=25) + +artmediumlbl=Label(text="Medium: ") +artmediumlbl.place(x=590, y=120, width=80, height=25) + +medium=StringVar(window) +artmedium=OptionMenu(window, medium, "Oil", "Watercolour", "Ink", "Acrylic") +artmedium.place(x=670, y=120, width=100, height=25) + +artpricelbl=Label(text="Price: ") +artpricelbl.place(x=770, y=120, width=80, height=25) +artprice=Entry(text="") +artprice.place(x=850, y=120, width=100, height=25) + +addartbtn=Button(text="Add Piece", command=addart) +addartbtn.place(x=110, y=150, width=130, height=25) + +clearartbtn=Button(text="Clear Piece", command=clearart) +clearartbtn.place(x=250, y=150, width=130, height=25) + +outputwindow=Listbox() +outputwindow.place(x=10, y=200, width=1000, height=350) + +clearoutputwindow=Button(text="Clear output", command=clearwindow) +clearoutputwindow.place(x=10, y=200, width=1000, height=350) + +viewallartists=Button(text="View All Artists", command=viewartists) +viewallartists.place(x=1020, y=230, width=155, height=25) + +viewallart=Button(text="View All Art", command=viewart) +viewallart.place(x=1020, y=260, width=155, height=25) + +searchartist=Entry(text="") +searchartist.place(x=1020, y=300, width=50, height=25) + +searchartistbtn=Button(text="Search by Artist", command=searchartistoutput) +searchartistbtn.place(x=1075, y=300, width=100, height=25) + +medium2=StringVar(window) + +searchmedium=OptionMenu(window, medium2, "Oil", "Watercolour", "Ink", "Acrylic") +searchmedium.place(x=1020, y=330, width=100, height=25) + +searchmediumbtn=Button(text="Search", command=searchmediumoutput) +searchmediumbtn.place(x=1125, y=330, width=50, height=25) + +minlbl=Label(text="Min: ") +minlbl.place(x=1020, y=360, width=75, height=25) + +maxlbl=Label(text="Max: ") +minlbl.place(x=1100, y=360, width=75, height=25) + +selectmin=Entry(text="") +selectmin.place(x=1020, y=380, width=75, height=25) + +selectmax=Entry(text="") +selectmax.place(x=1100, y=380, width=75, height=25) + +searchpricebtn=Button(text="Search by Price", command=searchbyprice) +searchpricebtn.place(x=1020, y=410, width=155, height=25) + +soldpiece=Entry(text="") +soldpiece.place(x=1020, y=450, width=50, height=25) + +soldbtn=Button(text="Sold", command=sold) +soldbtn.place(x=1075, y=450, width=100, height=25) + +window.mainloop() +db.close() \ No newline at end of file diff --git a/challenges146_150/readme.md b/challenges146_150/readme.md new file mode 100644 index 0000000..62e6010 --- /dev/null +++ b/challenges146_150/readme.md @@ -0,0 +1 @@ +files added by chemineer