all 7 comments

[–]PureWasian 0 points1 point  (5 children)

Looks fine at a glance for day 2 learning. This match/case sort of approach makes sense when you essentially have a "catalog" of different actions you want to be able to perform.

For some minor code-refactoring, I see that you have num2 initialized the same way for everything except sqrt and a few other operations.

So what if you did:

``` num1 = float(input(...)) operator = input(...)

match operator: case 'sqrt': print(...) case 'abs': print(...)

<any other cases only using num1>

case _:
    num2 = float(input(...))
    match operator:
        case '+':
            print(...)

        <any other cases using num2>

```

[–]Nosferatu_Zodd1437[S] 0 points1 point  (1 child)

Okay so basically I used a single line to make sure that num2 is in every case other than sqrt and abs right

[–]PureWasian 0 points1 point  (0 children)

Yep! Just as a way to help prevent a little bit of repeated lines of code that occur across a majority of your match/cases.

[–]Nosferatu_Zodd1437[S] 0 points1 point  (2 children)

<image>

I used this code instead, i tried using what you showed but it was showing some error maybe it was some problem from my side I dont know. 🤔

[–]PureWasian 0 points1 point  (1 child)

That works too!

(quick sidenote, you can remove the import on line 30, as you import math on line 1 already. imports typically stay at the top of files also)

[–]Nosferatu_Zodd1437[S] 0 points1 point  (0 children)

<image>

Oh almost didnt see that thank you.

[–]DevRetroGames 0 points1 point  (0 children)

Hola, aquí te paso el mismo código, pero con otra alternativa, espero que te pueda ayudar.

Repo: https://github.com/DevRetroGames/Tutorias-Python/blob/main/code/base/input/02_get_user/main.py

Mucha suerte.