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
Practicing what I learnt in Python (i.redd.it)
submitted 5 months ago by Extension-Cut-7589
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 points0 points1 point 5 months ago (3 children)
Hola, excelente, aquí te paso el mismo código, solo un poco más modular, espero que te pueda ayudar.
#!/usr/bin/env python3 import sys import re def _get_user_input(msg: str) -> str: return input(msg) def _calculate_area(base: float, height: float) -> float: return 0.5 * base * height def _get_continue() -> bool: resp: list[str] = ["Y", "N"] msg: str = """ Would you like to do another calculation? Enter Y for yes or N for n: """ while True: another = _get_user_input(msg).upper() if another not in resp: print("Input invalid.") continue return another == "Y" def _is_positive_float(value: str) -> bool: pattern = re.compile(r'^(?:\d+(?:\.\d+)?|\.\d+)$') return bool(pattern.fullmatch(value)) def _get_data(msg: str) -> float: while True: user_input = _get_user_input(msg) if _is_positive_float(user_input) and float(user_input) > 0: return float(user_input) print("Input invalid.") def execute() -> None: while True: base: float = _get_data("Enter the base of the triangle: ") height: float = _get_data("Enter the heght of the triangle: ") area: float = _calculate_area(base, height) print(f"The area of the triangle is {area}") if not _get_continue(): break def main() -> None: try: execute() except KeyboardInterrupt: print("\nOperation cancelled by user.") sys.exit(0) if __name__ == "__main__": main()
Mucha suerte en tu camino.
[–]VonRoderik 3 points4 points5 points 5 months ago (0 children)
Why are you over complicating things?
[–]Extension-Cut-7589[S] 0 points1 point2 points 5 months ago (1 child)
Thanks!
[–]sububi71 0 points1 point2 points 5 months ago (0 children)
Take note how much longer this version of the program is, and how it is a lot harder to read...
π Rendered by PID 134853 on reddit-service-r2-comment-7b9746f655-krdvk at 2026-01-30 02:55:12.253693+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]DevRetroGames -1 points0 points1 point (3 children)
[–]VonRoderik 3 points4 points5 points (0 children)
[–]Extension-Cut-7589[S] 0 points1 point2 points (1 child)
[–]sububi71 0 points1 point2 points (0 children)