diff --git a/Todoapp/README.md b/Todoapp/README.md new file mode 100644 index 0000000000..880323b5ec --- /dev/null +++ b/Todoapp/README.md @@ -0,0 +1,7 @@ +Created a todo applist in pyhton + +1) Fork this repository + +2) Run todo.py + +3) That's it! add the check lists and get things done. diff --git a/Todoapp/screenshot.JPG b/Todoapp/screenshot.JPG new file mode 100644 index 0000000000..c9d2a996a4 Binary files /dev/null and b/Todoapp/screenshot.JPG differ diff --git a/Todoapp/todo.py b/Todoapp/todo.py new file mode 100644 index 0000000000..d15cf94c6c --- /dev/null +++ b/Todoapp/todo.py @@ -0,0 +1,91 @@ +import tkinter +import threading +from tkinter import messagebox +import sys + +tasks = [] +timer = threading +real_timer = threading +ok_thread = True + + +def get_entry(event=""): + text = todo.get() + hour = int(time.get()) + todo.delete(0, tkinter.END) + time.delete(0, tkinter.END) + todo.focus_set() + add_list(text, hour) + if 0 < hour < 999: + update_list() + + +def add_list(text, hour): + tasks.append([text, hour]) + timer = threading.Timer(hour, time_passed, [text]) + timer.start() + + +def update_list(): + if todolist.size() > 0: + todolist.delete(0, "end") + for task in tasks: + todolist.insert("end", "[" + task[0] + "] Time left: " + str(task[1]) + " secondes") + + +def time_passed(task): + tkinter.messagebox.showinfo("Notification", "Time for : " + task) + + +def real_time(): + if ok_thread: + real_timer = threading.Timer(1.0, real_time) + real_timer.start() + for task in tasks: + if task[1] == 0: + tasks.remove(task) + task[1] -= 1 + update_list() + + +if __name__ == '__main__': + # application + app = tkinter.Tk() + app.geometry("480x680") + app.title("Todolist Remainder") + app.rowconfigure(0, weight=1) + + # fenetre + frame = tkinter.Frame(app) + frame.pack() + + # widgets + label = tkinter.Label(app, text="Enter work to do:", + wraplength = 200, + justify = tkinter.LEFT) + label_hour = tkinter.Label(app, text="Enter time (secondes)", + wraplength = 200, + justify = tkinter.LEFT) + todo = tkinter.Entry(app, width=30) + time = tkinter.Entry(app, width=15) + send = tkinter.Button(app, text='Add task', fg="#ffffff", bg='#6186AC', height=3, width=30, command=get_entry) + quit = tkinter.Button(app, text='Exit', fg="#ffffff", bg='#EB6464', height=3, width=30, command=app.destroy) + todolist = tkinter.Listbox(app) + if tasks != "": + real_time() + + # binding + app.bind('', get_entry) + + # widgets placement + label.place(x=0, y=10, width=200, height=25) + label_hour.place(x=235, y=10, width=200, height=25) + todo.place(x=62, y=30, width=200, height=25) + time.place(x=275, y=30, width=50, height=25) + send.place(x=62, y=60, width=50, height=25) + quit.place(x=302, y=60, width=50, height=25) + todolist.place(x=60, y = 100, width=300, height=300) + + app.mainloop() + ok_thread = False + sys.exit("FINISHED") diff --git a/tictactoe/README.md b/tictactoe/README.md new file mode 100644 index 0000000000..38dde21db0 --- /dev/null +++ b/tictactoe/README.md @@ -0,0 +1,11 @@ +

TIC-TAC-TOE

+ +The game is automatically played by the program and hence, no user input is needed. Still, developing a automatic game will be lots of fun! + +

How to use?

+ +1)clone the repository + +2)Run tictactoe.py + +3)see the output of screenshot as in folder diff --git a/tictactoe/output.JPG b/tictactoe/output.JPG new file mode 100644 index 0000000000..e22a7e6378 Binary files /dev/null and b/tictactoe/output.JPG differ diff --git a/tictactoe/tictactoe.py b/tictactoe/tictactoe.py new file mode 100644 index 0000000000..9e2de278d8 --- /dev/null +++ b/tictactoe/tictactoe.py @@ -0,0 +1,116 @@ +# Tic-Tac-Toe Program using +# random number in Python + +# importing all necessary libraries +import numpy as np +import random +from time import sleep + +# Creates an empty board +def create_board(): + return(np.array([[0, 0, 0], + [0, 0, 0], + [0, 0, 0]])) + +# Check for empty places on board +def possibilities(board): + l = [] + + for i in range(len(board)): + for j in range(len(board)): + + if board[i][j] == 0: + l.append((i, j)) + return(l) + +# Select a random place for the player +def random_place(board, player): + selection = possibilities(board) + current_loc = random.choice(selection) + board[current_loc] = player + return(board) + +# Checks whether the player has three +# of their marks in a horizontal row +def row_win(board, player): + for x in range(len(board)): + win = True + + for y in range(len(board)): + if board[x, y] != player: + win = False + continue + + if win == True: + return(win) + return(win) + +# Checks whether the player has three +# of their marks in a vertical row +def col_win(board, player): + for x in range(len(board)): + win = True + + for y in range(len(board)): + if board[y][x] != player: + win = False + continue + + if win == True: + return(win) + return(win) + +# Checks whether the player has three +# of their marks in a diagonal row +def diag_win(board, player): + win = True + y = 0 + for x in range(len(board)): + if board[x, x] != player: + win = False + if win: + return win + win = True + if win: + for x in range(len(board)): + y = len(board) - 1 - x + if board[x, y] != player: + win = False + return win + +# Evaluates whether there is +# a winner or a tie +def evaluate(board): + winner = 0 + + for player in [1, 2]: + if (row_win(board, player) or + col_win(board,player) or + diag_win(board,player)): + + winner = player + + if np.all(board != 0) and winner == 0: + winner = -1 + return winner + +# Main function to start the game +def play_game(): + board, winner, counter = create_board(), 0, 1 + print(board) + sleep(2) + + while winner == 0: + for player in [1, 2]: + board = random_place(board, player) + print("Board after " + str(counter) + " move") + print(board) + sleep(2) + counter += 1 + winner = evaluate(board) + if winner != 0: + break + return(winner) + +# Driver Code +print("Winner is: " + str(play_game()))