online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
''' Python 3.10+ required due to the use of: match read more: https://learnpython.com/blog/python-match-case-statement/ ''' from dateutil.relativedelta import relativedelta from datetime import datetime import calendar import os def clearScreen(): os.system('cls' if os.name in ('nt', 'dos') else 'clear') def show_age(year, month, day, selection): birth_date = datetime(year, month, day) delta = relativedelta(datetime.now(), birth_date) match selection: case '1': date_diff = datetime.now() - birth_date return f'you are {date_diff.days} days old' case '2': return f'you are {delta.months} months old and {delta.days} days old' case '3': print(("Damn. That's old!", 'Good for you!') [delta.years < 36]) return f'you are {delta.years} years, {delta.months} months and {delta.days} days old' case _: # default action pass repeat = 'y' name = input('Hello. What is your name? ') while repeat in ['y', 'Y']: clearScreen() while True: try: birth_year = int(input(f'Hello {name} what year were you born? ')) if not len(str(birth_year)) == 4: print('Year must to be four digits number') #elif not birth_year in range(1800, datetime.now().year + 1): # print('Your text about birth_year - out of range') else: break except ValueError: print('Use only digits') while True: try: birth_month = int(input('What month numerically? (EX: December=12) ')) if not len(str(birth_month)) in [1, 2]: print('Month must to be one or two digits number') elif not birth_month in range(1,13): print('Wrong month number') else: break except ValueError: print('Use only digits') while True: try: birth_day = int(input(f'And what day of the month of {calendar.month_name[birth_month]}? ')) if not len(str(birth_day)) in [1, 2]: print('Day must to be one or two digits number') elif not birth_day in range(1,32): print('Wrong day number') else: break except ValueError: print('Use only digits') while True: print('\n SEE YOUR EXACT AGE IN:') print(' 1. DAYS ONLY \n 2. MONTHS AND DAYS ONLY \n 3. YEARS MONTHS AND DAYS') selection = input('\nENTER A NUMBER: ') if not selection in ['1', '2', '3']: print('Please, use right option number') else: break clearScreen() print(name, show_age(birth_year, birth_month, birth_day, selection)) repeat = input('\nWould you like to try again? (Y/N): ') clearScreen() print('Thanks for stopping by', name)

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue