Review of date format
Write a program to format to format yyyy/mm/dDReceive from the user and check whether the date received in the correct format is correct.
Example:
Write a program to format to format yyyy/mm/dDReceive from the user and check whether the date received in the correct format is correct.
Example:
def tariag ( sal , mah , ros ) :
if mah == 4 and sal == 2008 and ros == 13 :
return True
return 'error '
sal = int (input ('sal : '))
mah = int (input ('mah : '))
ros = int (input ('ros : '))
n = tariag (sal , mah , ros)
print (n)
y = int(input('enter the year : ')) m = int(input('enter the month : ')) d = int(input('enter the day : ')) if m > 12 and d > 30 : print('false') else : print('true')
import jdatetime
year = int(input("entry your year:"))
month = int(input("enter your month:"))
day = int(input("entter your day:"))
x = jdatetime.date.fromgregorian(year = year , month = month , day = day)
print(x)
date1 = jdatetime.date.today()
print(date1)
if x == date1:
print(True)
if x != date1:
print(False)
year = int(input("entry your year:"))
month = int(input("enter your month:"))
day = int(input("entter your day:"))
print(f"{year}:{month}:{day}")
if month > int(12) and day > int(31):
print("tarikh dar fomat eshtebah ast")
else:
print("tarikh dar format dorosh ast")
import re from datetime import datetime def is_valid_date(date_string): # Review of date format using Regex pattern = r'^\d{4}/\d{2}/\d{2}$' if not re.match(pattern, date_string): return False # Convert the history of history to the Datetime object and examine the accuracy of history try: year, month, day = map(int, date_string.split('/')) datetime(year, month, day) return True except ValueError: return False def main(): date_input = input("تاریخ را به فرمت yyyy/mm/dd وارد کنید: ") is_valid = is_valid_date(date_input) print(is_valid) if __name__ == "__main__": main()
user_date = input("Please enter date: (format: yyyy/mm/dd)") lst_date = user_date.split("/") if 0 < int(lst_date[1]) <= 12 and 0 < int(lst_date[2]) <= 31: print(True) else: print(False)
from datetime import datetime user_date = input("Please enter date: (format: yyyy/mm/dd)") try: datetime.strptime(user_date, "%Y/%m/%d") print (True) except : print (False)
year = int(input("year: ")) month = int(input("month: ")) day = int(input("day: ")) format_ymd = f"{year}/{month}/{day}" if year > 2025: print(f"History : {format_ymd} year error") print("False") elif month > 12: print(f"History : {format_ymd} month error") print("False") elif month > 30: print(f"History : {format_ymd} day error") print("False") elif year < 2025 and month < 13 and day < 31: print(f"History : {format_ymd}") print("True") else: print("Not")
tarikh = int(input("tarikh miladi":) sal = tarikh[0:4] mah=tarikh[4:6] rooz=tarikh[6:8] mah ={"1":"jan" ,"2": "feb", "3": "mar" ,"4":"apr" , "5": "may" ,"6": "jun" , "7":"jul" , "8": "Aug" , "9": "sep" , "10": "oct", "11": "nov" , "12": "dec" } if tarikh in mah : print(" true ") else: print("false")
Submitting answers is currently unavailable.
Write a program that receives 2 numbers from the input and prints the larger number
Write a function that receives the number of hours of employee work per month as a parameter and calculates the amount of employee salaries according to the formula below and returns each employee for 2 hours of work per month, per hour at 4 ...
The program receives the amount of distance traveled to kilometers and the amount of fuel consumed in liter and prints according to the following instructions, whether the car is low or high. If the fuel consumption of this car is less than 7 liters ...
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام 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.