0% found this document useful (0 votes)
5 views

Alarm

Uploaded by

aeyoaaeyoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Alarm

Uploaded by

aeyoaaeyoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import datetime

import random
import time

def ask_math_question(grade):
# ‫يقوم بطرح مسألة رياضية بناًء على الصف الدراسي‬
if grade == "4":
num1 = random.randint(1, 20)
num2 = random.randint(1, 20)
elif grade == "7":
num1 = random.randint(20, 50)
num2 = random.randint(20, 50)
elif grade == "10":
num1 = random.randint(50, 100)
num2 = random.randint(50, 100)
else:
print("Invalid grade. Setting to grade 4 by default.")
num1 = random.randint(1, 20)
num2 = random.randint(1, 20)

operator = random.choice(['+', '-', '*'])


question = f"What is {num1} {operator} {num2}? "
if operator == '+':
answer = num1 + num2
elif operator == '-':
answer = num1 - num2
else:
answer = num1 * num2
return question, answer

def alarm_clock():
# ‫تحديد وقت الإنذار‬
alarm_time = input("Enter the alarm time in HH:MM format: ")
grade = input("Enter your current grade (4, 7, 10): ")

while True:
current_time = datetime.datetime.now().strftime("%H:%M")
if current_time == alarm_time:
print("Wake up!")
question, answer = ask_math_question(grade)
user_answer = input(question)
while True:
try:
user_answer = int(user_answer)
break
except ValueError:
print("Please enter a valid number.")
user_answer = input(question)
while user_answer != answer:
print("Oops! That's incorrect. Try again!")
user_answer = input(question)
try:
user_answer = int(user_answer)
except ValueError:
print("Please enter a valid number.")
time.sleep(60) # ‫التحقق من الوقت كل دقيقة‬

if __name__ == "__main__":
alarm_clock()

You might also like