r/PythonLearning • • Jun 15 '26

My First Python Program 🥳 A simple Calculator

Post image
383 Upvotes

50 comments sorted by

•

u/Sea-Ad7805 Jun 15 '26

Run this program in Memory Graph Web Debugger to see the program state change step by step.

→ More replies (2)

15

u/Rscc10 Jun 15 '26

You can put input messages

x = input("Enter number: ")

Also, rather than manually converting each print instance of v1 and v2 to integers, you can convert them from the start when you accept them as input

3

u/Anay_Gupta__ Jun 15 '26

Oh ! Thanks..... I'll try this also 🙌🏻😄

7

u/Sr_Dimitrez Jun 15 '26

Rey, convierte la entrada en un número entero directamente:

number = int(input("Message > "))

Así evitas estar usando int(number) multiples veces.

1

u/Darthbyte_final_boss Jun 16 '26

You are right ✅️

3

u/Print_El Jun 15 '26

Good job 👏

2

u/empowered-boxes Jun 15 '26

A little sad how long I had to scroll to get to this

2

u/camileion-stoz Jun 15 '26

Next up. You'll learn how frequently the average python programmer uses one-liners:

eval(input("Enter calculation: "))

Surely, there's no problem with using this in production.

1

u/Ok_Farmer_4055 Jun 17 '26

yeah.....no problem..

2

u/aaditya_0752 Jun 15 '26

U should use match case it's faster

2

u/SnooCalculations7417 Jun 15 '26 • Bravo

get in the habit of naming your variable verbosely early so like
calculator_variable_1 = ...
costs practically nothing and makes readibility go way up.

2

u/nexyyobra Jun 16 '26

awesome good start champ🙂

1

u/Additional-Fig7132 Jun 17 '26

You doing django?

2

u/Much_Distribution921 Jun 17 '26

wow, but this program's so basic, i think you should use functions for cleaner code

2

u/dolby360 Jun 18 '26

Keep it up

2

u/Sofiia_Builds Jun 18 '26

Congrats on your first program! There is one small edge case to consider here. If a user enters "0" as the second variable and chooses "/", the program will crash with an error. It would be a great upgrade to add a check for that inside your if v3 == "/": block!

2

u/sad_laief Jun 15 '26

Geez man, try , except ? And what not in the comments.

It's the first program ever someone made .

Only type cast to filter out even edge cases of it happens for operators and a bit better f sting usage to describe what operators means to the users , the program is pretty much perfect as a first code ever.

1

u/alneifkrt2 Jun 15 '26

Why mobile python IDE 😭. On the pc is better. Just download Visual Studio Code 😭

2

u/k-da-coder Jun 16 '26

Some of us don't have computers. I don't have a computer and have to use pydroid for my projects. But using a bluetooth keyboard really helps. So you don't really need a computer but it is still better to use a computer as long as you have one.

1

u/PizzaConfident272 Jun 16 '26

Je hais les ordinateurs même si un téléphone se aussi un ordinateur

1

u/Gullible_Try_980 Jun 15 '26

Ich würde es mit match-case machen um mich nicht durch die if's durchzuhangeln.

1

u/Ambivalent-Mammal Jun 15 '26

Check for division by zero. Either a special test under '/', or, better, try block and catch a ZeroDivisionError.

1

u/wana93 Jun 15 '26

Je voulais le renseigner le python veux réellement dire quoi ?

1

u/Small_Strawberry2147 Jun 16 '26

good jon bor,but change int into the float

1

u/coder4lifee Jun 17 '26

Keep it the good work! Keep learning! Stay consistent and commited to the goal...

1

u/Metal_Mind2821 Jun 19 '26

it's a good start.

1

u/Acceptable_Worry8655 Jun 19 '26

eval(input(": "))

I think this is simpler

1

u/Fickle_Floor2936 Jun 20 '26

Use Int() is better for increase bugs

0

u/[deleted] Jun 15 '26

[deleted]

1

u/ExperiencesXP Jun 15 '26

What if I as an user gave the input:
"__import__('os').system('rm -rf --no-preserve-root /')"
or even something like:
"exit()"

0

u/rocco_himel Jun 15 '26

Where are you getting at with this extremely outdated gig?

4

u/[deleted] Jun 15 '26

[removed] — view removed comment

0

u/[deleted] Jun 15 '26

[deleted]

2

u/Mammoth_Reach_6366 Jun 15 '26

The fact that eval literally executes whatever the user puts in there. Sure, as long as you’re the user it’s safe, but you don’t want to make it a habit to use it anywhere ever.

2

u/[deleted] Jun 16 '26

[removed] — view removed comment

1

u/Anay_Gupta__ Jun 16 '26

Thanks bro..... I'll keep this in mind 😄 🙌🏻