From 008f1d75c35224b7437b6a34b67c409eacbc0589 Mon Sep 17 00:00:00 2001 From: Mayuri Date: Sun, 9 Oct 2022 20:46:20 +0530 Subject: [PATCH] added alarm and number guessing --- scripts/Number guessing game/numberGuess.py | 25 ++++++ scripts/Number guessing game/readme.md | 5 ++ scripts/alarmclock/alarm.py | 86 +++++++++++++++++++++ scripts/alarmclock/readme.md | 9 +++ 4 files changed, 125 insertions(+) create mode 100644 scripts/Number guessing game/numberGuess.py create mode 100644 scripts/Number guessing game/readme.md create mode 100644 scripts/alarmclock/alarm.py create mode 100644 scripts/alarmclock/readme.md diff --git a/scripts/Number guessing game/numberGuess.py b/scripts/Number guessing game/numberGuess.py new file mode 100644 index 0000000..428f509 --- /dev/null +++ b/scripts/Number guessing game/numberGuess.py @@ -0,0 +1,25 @@ +import random +t = 0 +g = int(input("Total Guesses: ")) +low = int(input("Enter the lower range: ")) +high = int(input("Enter the upper range: ")) +x = random.randint(low, high) +n = int(input("Enter an integer between the given range: ")) + +while (x != 'n'): + if(t<(g-1)): + if n < x: + print("The number guessed is low") + t = t+1 + n = int(input("Enter an integer between the given range: ")) + elif (n > x): + print("The number guessed is high") + t = t+1 + n = int(input("Enter an integer between the given range: ")) + else: + print("The number guessed is right") + print("Total guesses taken: ", t+1) + break + else: + print("Ran out of tries!") + break \ No newline at end of file diff --git a/scripts/Number guessing game/readme.md b/scripts/Number guessing game/readme.md new file mode 100644 index 0000000..7244c69 --- /dev/null +++ b/scripts/Number guessing game/readme.md @@ -0,0 +1,5 @@ +###Number guessing Game in Python + +#Steps +*Run python numberGuess.py +*Enjoy the game....! \ No newline at end of file diff --git a/scripts/alarmclock/alarm.py b/scripts/alarmclock/alarm.py new file mode 100644 index 0000000..eb1e869 --- /dev/null +++ b/scripts/alarmclock/alarm.py @@ -0,0 +1,86 @@ +# 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()}" + + # Wait for one seconds + time.sleep(1) + + # Get current time + current_time = datetime.datetime.now().strftime("%H:%M:%S") + print(current_time,set_alarm_time) + + # Check whether set alarm is equal to current time or not + if current_time == set_alarm_time: + print("Time to Wake up") + # Playing sound + winsound.PlaySound("sound.wav",winsound.SND_ASYNC) + +# Add Labels, Frame, Button, Optionmenus +Label(root,text="Alarm Clock",font=("Helvetica 20 bold"),fg="red").pack(pady=10) +Label(root,text="Set Time",font=("Helvetica 15 bold")).pack() + +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]) + +hrs = OptionMenu(frame, hour, *hours) +hrs.pack(side=LEFT) + +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]) + +mins = OptionMenu(frame, minute, *minutes) +mins.pack(side=LEFT) + +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]) + +secs = OptionMenu(frame, second, *seconds) +secs.pack(side=LEFT) + +Button(root,text="Set Alarm",font=("Helvetica 15"),command=Threading).pack(pady=20) + +# Execute Tkinter +root.mainloop() \ No newline at end of file diff --git a/scripts/alarmclock/readme.md b/scripts/alarmclock/readme.md new file mode 100644 index 0000000..fa8467c --- /dev/null +++ b/scripts/alarmclock/readme.md @@ -0,0 +1,9 @@ +#Alarm clock Using Python +Simple GUI thats let you set alarm. + +##Usage +* packages required Tkinter +* Use pip install tkinter +*Other requirements include - datetime , time , winsound . Import them from python +*Run python alarm.py +