r/learnprogramming • • 9d ago

Rate my first project

Hello! I've started learning python abt 2 weeks ago and till now, I just know the basics. I've created my very first project on my own (I only asked ChatGPT for project ideas but the rest was on me) and this is what I've done in abt an hour.

I'd like you guys to tell me how can I get better. I know many things are may be missing regarding calculations and operators.

print("===========================================")
print()
print()
print("     BASIC & ENGINEERING CALCULATOR   ")
print()
print()
print("===========================================")
calc_type = input("What type of calculator do you want to use?: Basic, Engineering ").capitalize().strip()
if calc_type =="Basic":
    operator = input("Enter the operator (+, -, *, /, ^):")
    num1 = float(input("Enter the first number:"))
    num2 = float(input("Enter the second number:"))
    if operator == '+':
        result = num1 + num2
        print(f"The result of adding {num1} and {num2} is: {round(result,2)}")
    elif operator == '-':
        result = num1 - num2
        print(f"The result of subtracting {num1} and {num2} is: {round(result,2)}")
    elif operator == '*':
        result = num1 * num2
        print(f"The result of multiplying {num1} by {num2} is: {round(result,2)}")
    elif operator == '/':
        result = num1 / num2
        print(f"The result of dividing {num1} by {num2} is: {round(result,2)}")
    elif operator == '^':
        result = num1 ** num2
        print(f"The result of raising {num1} to {num2} is: {round(result,2)}")
    else: 
        print("Enter a valid operator!")
elif calc_type == "Engineering":
    calculations=input("What do you want to calculate?: Force, Density, Speed ").capitalize().strip()
    if calculations == "Force":
        mass= float(input("Enter the mass value: "))
        acceleration= float(input("Enter the acceleration value: "))
        Force = mass * acceleration
        print(f"The Force is equal to {round(Force,2)} N.")
    elif calculations == "Density":
        mass= float(input("Enter the mass value: "))
        volume= float(input("Enter the volume value: "))
        Density = mass/volume
        print(f"The Density value is {round(Density,2)} kg/m^3 ")
    elif calculations == "Speed":
        distance = float(input("Enter the distance travelled: "))
        time = float(input("Enter the time in seconds:"))
        Speed = distance/time
        print(f"The Speed is {Speed} m/s")
    else: 
        print("Enter a valid calculation type!")
else:
    print("We only offer Basic & Engineering calculations")
4 Upvotes

8 comments sorted by

1

u/NomaTyx 9d ago

for two weeks, not bad! I have a question, what happens if I choose division, and then enter 1 and 0?

2

u/isalihhh 8d ago

ZeroDivisionError. I haven't added a condition for that so I'm going to improve the project by tomorrow and add more features and also solve errors

1

u/CorpT 9d ago

1.5/10

2

u/isalihhh 8d ago

I’ll count that as 15/10🙄

1

u/quiet_stacktrace 8d ago

nice for two weeks. since you're using float(input()), typing a letter will crash it with a ValueError, so wrapping those in a try/except ValueError and asking again is a good next thing to learn

1

u/dahiya_xa 8d ago

nice for two weeks in. next things i'd try: wrap the input in try/except so typing a letter doesn't crash it, check for dividing by zero, and put the whole thing in a while loop so you can do more than one calculation. after that, move each operation into its own function, it'll make the engineering part way easier to add to

1

u/YogurtclosetLow7064 2d ago

Nice for two weeks. I especially like that you built it yourself without relying on AI to write the code. Keep practicing and improving it step by step