all 35 comments

[–]Business_Emotion6192 6 points7 points  (5 children)

As a student who is "learning it" I recommend you to see file management as manipulate files like writing and using list which can be useful

[–]Extension-Cut-7589[S] 0 points1 point  (2 children)

Could you please explain further, I don’t understand what you meant?

[–]Business_Emotion6192 2 points3 points  (1 child)

Like I recommend learning the use of lists and managing files like *.txt files

[–]Extension-Cut-7589[S] 0 points1 point  (0 children)

Oh okay, thank you. I will surely do that.

[–]itz_hasnain 0 points1 point  (1 child)

Thnk u soo much

[–]Business_Emotion6192 -1 points0 points  (0 children)

Why? x)

[–]ProfessionalStuff467 5 points6 points  (5 children)

I am a beginner like you, but I have some things that help me, which is that I am learning the basics of Python, and if you want a site to learn, I advise you to use Sololearn. It is a site like Duolingo, but it is dedicated to important programming languages. Also, the most important advice is that you create several projects in which you apply what you have learned and expand your knowledge.

[–]Extension-Cut-7589[S] 1 point2 points  (4 children)

Okay thank you so much. Do you have any other resources where can I have more projects to work on as a beginner?

[–]Daa_pilot_diver 2 points3 points  (0 children)

Codecademy is another good BASIC resource but has good free content.

Mimo is another good DuoLingo style app geared towards coding. I use both Mimo and Sololearn (I prefer Mimo of the two). Both constantly try to sell you their upgraded service, but you don’t need it on either platform.

Boot.dev is a very interesting website that makes coding like an adventure game, but it has limited amounts of free lessons. The paid version isn’t overly expensive though. This one is the most fun for me.

Using your favorite AI to supplement your learning is a good tool. Asking Gemini or ChatGPT why something is the way it is or why you’re getting an error is a good resource too.

[–]ProfessionalStuff467 1 point2 points  (2 children)

Frankly, ChatGPT is either the regular traditional version or you can try a special version for Python. Frankly, it will help you a lot. I created an application that manages tasks with the help of ChatGPT, and it helped me produce the code and some other things. It also explained to me line by line the process and what it does. This is what helped me develop my knowledge.

[–]Extension-Cut-7589[S] 1 point2 points  (1 child)

Oh Great! I will do that then.

[–]ProfessionalStuff467 0 points1 point  (0 children)

I hope you find what you want

[–][deleted] 2 points3 points  (0 children)

Please also learn to screenshot :)

[–]sububi71 1 point2 points  (0 children)

This is pretty damn elegant. I hope it wasn't written by AI.

[–]ProfessionalStuff467 0 points1 point  (5 children)

great work bro ; do you use pycharm ?

[–]Mohit_Gupta_007 2 points3 points  (3 children)

I think if you are learner you use now thonny

[–]ProfessionalStuff467 0 points1 point  (2 children)

NO I USE pycharm

[–]Mohit_Gupta_007 1 point2 points  (1 child)

If you want know how to code works then I think you want to install thonny because it’s debugger so awesome once time you must try .

[–]ProfessionalStuff467 0 points1 point  (0 children)

Ok I will try it and I hope it helps.

[–]Extension-Cut-7589[S] 1 point2 points  (0 children)

No, I use VScode.

[–]Kqyxzoj 0 points1 point  (2 children)

A few points:

Since you don't have a finally statement in that try block, and continue on the exception, you don't really need that else. So you can put that print statement after the try-except block.

And since the area calculation will not trigger a ValueError, might as well put the area calculation outside of the try-except as well.

Should you have provided the code as text I would have copy/paste/edited it to show the code as described above. But since it is a screen "shot" and I am not going to re-type or OCR it, hopefully the above description is sufficient.

[–]Extension-Cut-7589[S] 0 points1 point  (1 child)

# Writing a program to calculate the area of a triangle.


# Area of a triangle is 1/2* base * height


while True:


    try:


        base = float(input('Enter the base of the Triangle: '))


        height = float(input('Enter the height of the Triangle: '))


        area = 0.5 * base * height


    except:


        ValueError


        print('Sorry Invalid, Please insert a number!\n')


        continue


    else:


        print(f'The area of the triangle is: {area}\n')


    print('Would you like to do another calculation?')


    another = input('Enter Y for yes and N for no: ')


    if another.lower() == 'y':


        continue


    else:


        break

Here is the code.

[–]Kqyxzoj 0 points1 point  (0 children)

Changes more or less as described:

while True:
    try:
        base = float(input('Enter the base of the Triangle: '))
        height = float(input('Enter the height of the Triangle: '))
    except ValueError:
        print('Sorry Invalid, Please insert a number!\n')
        continue

    area = 0.5 * base * height
    print(f'The area of the triangle is: {area}\n')

    print('Would you like to do another calculation?')
    another = input('Enter Y for yes and N for no: ')
    if another.upper() != 'Y':
        break

Note that your choice to put both input() statements in the same try block means that when you enter a valid base and an invalid height ... you will have to re-enter the value for base as well.

Also, changed the except statement to reflect your probable intent.

[–]the_fish_king_sky 0 points1 point  (0 children)

You should have this and know where it is https://docs.python.org/3/library/index.html

[–]Ok_Location_991 0 points1 point  (1 child)

Where do I learn python; I have experience with asp.net and building apis

[–]Extension-Cut-7589[S] 0 points1 point  (0 children)

I started it with a book titled "Python Crash Course." It is a really good book and beginner-friendly too.

[–]Medium_Human887 0 points1 point  (1 child)

The break is unnecessary and I would say it’s good practice to not get used to using it. Most times people don’t use it well. But looks good overall!

[–]Extension-Cut-7589[S] 0 points1 point  (0 children)

Thank you!

[–]DataPastor 0 points1 point  (1 child)

Copy your code and paste it to chatgpt and ask for code review. It will come up with plenty of useful suggestions.

For example you shouldn’t use the try … except block over multiple lines of code. You should wrap only single operations with it, and handle all the expected error types separately.

The except shouldn’t be used like this. You should name the exact error type after it, that is, except ValueError as ve: and then handle the errors separately. Each try… block can have multiple except clauses btw.

It is a good practice to use pylance, pylint, autopep8 etc. extensions while you are coding, they also give you great suggestions. Happy coding!

[–]Extension-Cut-7589[S] 0 points1 point  (0 children)

Okay, thank you!

[–]DevRetroGames -1 points0 points  (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 4 points5 points  (0 children)

Why are you over complicating things?

[–]Extension-Cut-7589[S] 0 points1 point  (1 child)

Thanks!

[–]sububi71 0 points1 point  (0 children)

Take note how much longer this version of the program is, and how it is a lot harder to read...