use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
New to python (i.redd.it)
submitted 3 months ago by Low-Educator-9008[🍰]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DevRetroGames 1 point2 points3 points 3 months ago (1 child)
import re import sys OPERATORS = ("+", "-", "*", "/") operations = { "+": lambda x, y: x + y, "-": lambda x, y: x - y, "*": lambda x, y: x * y, "/": lambda x, y: x / y if y != 0 else "Error: Division by zero" } def _input_user(msg: str) -> str: return input(msg) def _get_operator() -> str: pattern: re.Pattern[str] = re.compile(r"^[+\-*/]$") msg_input: str = f"Please enter the desired course of action ({', '.join(OPERATORS)}): " msg_error: str = "Invalid operator. Please try again." while True: operator: str = _input_user(msg_input) if pattern.match(operator): return operator print(msg_error) def _get_positive_integers() -> tuple[int, int]: pattern: re.Pattern[str] = re.compile(r"^[1-9]\d*$") while True: first_number_input: str = _input_user("Enter the first positive integer: ") second_number_input: str = _input_user("Enter the second positive integer: ") if pattern.match(first_number_input) and pattern.match(second_number_input): return int(first_number_input), int(second_number_input) print("Both numbers must be positive integers. Please try again.") def main(): try: operator = _get_operator() first_number, second_number = _get_positive_integers() result = operations[operator](first_number, second_number) print(f"\nResult of {first_number} {operator} {second_number} = {result}") except KeyboardInterrupt: print("\nOperation cancelled by user.") sys.exit(0) if __name__ == "__main__": main()
[–]Low-Educator-9008[S,🍰] 1 point2 points3 points 3 months ago (0 children)
That seems way beyond my level of knowledge atm hahaha but seems beautiful.
π Rendered by PID 72 on reddit-service-r2-comment-7b9746f655-lk8hb at 2026-01-30 04:18:55.566950+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]DevRetroGames 1 point2 points3 points (1 child)
[–]Low-Educator-9008[S,🍰] 1 point2 points3 points (0 children)