The alarm
Write a program that receives hours and minutes from the user and the alarm at the specified time
Write a program that receives hours and minutes from the user and the alarm at the specified time
import time import datetime def set_alarm(alarm_time): print(f"زنگ هشدار برای ساعت {alarm_time} تنظیم شد.") while True: # Receive current time current_time = datetime.datetime.now().strftime("%H:%M") if current_time == alarm_time: print("زنگ هشدار! زمان آن رسیده است!") # Play the alarm # In Windows you can use WinSound # import winsound # winsound.Beep(1000, 1000) # 1000 Hz frequency for 1000 mm # You can use PlaySound for other operating systems from playsound import playsound playsound('alarm_sound.mp3') # Alarm file name break time.sleep(30) # Check every 30 seconds # Receive hours and minutes from the user hour = input("لطفاً ساعت را وارد کنید (HH): ") minute = input("لطفاً دقیقه را وارد کنید (MM): ") # Combination of hours and minutes to format HH: mm alarm_time = f"{hour}:{minute}" # Set the alarm alarm set_alarm(alarm_time)
import time import winsound # For Windows # Use PlaySound if you are on Linux or Mac. def alarm_clock(hour, minute): # Convert hours and minutes to current time while True: current_time = time.localtime() current_hour = current_time.tm_hour current_minute = current_time.tm_min # Check time if current_hour == hour and current_minute == minute: print("زنگ هشدار! زمان مشخص شده فرا رسیده است.") # Play the alarm winsound.Beep(1000, 1000) # Alarm (1000 Hz for 1 second) break # Sleeping for 30 seconds before checking again time.sleep(30) if __name__ == "__main__": # Receive hours and minutes from the user hour = int(input("لطفاً ساعت (0-23) را وارد کنید: ")) minute = int(input("لطفاً دقیقه (0-59) را وارد کنید: ")) # Alarm alarm_clock(hour, minute)
Submitting answers is currently unavailable.
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.