create account

Basic Calculator - Learning to Code by paulmoon410

View this thread on: hive.blogpeakd.comecency.com
· @paulmoon410 · (edited)
$0.88
Basic Calculator - Learning to Code
<center>![](https://images.ecency.com/DQmT6JB3C3LGfDXWnuMYuCcVFdknKbXrywUQakGHfKnuYzC/image.png)
</center>

If you're interested in learning coding this is a basic calculator you can use and play around with. 

Its also on github. https://github.com/PaulMoon410/learn_calc


Python Coded
#### clock.py
````html 

# Thank you to those at Learn To Code on Hive.io

#  adds two numbers
def add(x, y):
    return x + y

#  subtracts two numbers
def subtract(x, y):
    return x - y

# multiplies two numbers
def multiply(x, y):
    return x * y

# divides two numbers
def divide(x, y):
    return x / y


print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

while True:
    # input from the user
    choice = input("Enter choice(1/2/3/4): ")

    # check if choice is one of the four options
    if choice in ('1', '2', '3', '4'):
        try:
            num1 = float(input("Enter first number: "))
            num2 = float(input("Enter second number: "))
        except ValueError:
            print("Invalid input. Please enter a number.")
            continue

        if choice == '1':
            print(num1, "+", num2, "=", add(num1, num2))

        elif choice == '2':
            print(num1, "-", num2, "=", subtract(num1, num2))

        elif choice == '3':
            print(num1, "*", num2, "=", multiply(num1, num2))

        elif choice == '4':
            print(num1, "/", num2, "=", divide(num1, num2))
        
        # check if user wants another calculation
        # break the while loop if answer is no
        next_calculation = input("Let's do next calculation? (yes/no): ")
        if next_calculation == "no":
          break
    else:
        print("Invalid Input")
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorpaulmoon410
permlinkbasic-calculator-learning-to-code
categoryhive-188262
json_metadata"{"app":"ecency/3.2.0-vision","description":"So... its a calculator","format":"markdown+html","image":["https://images.ecency.com/DQmT6JB3C3LGfDXWnuMYuCcVFdknKbXrywUQakGHfKnuYzC/image.png"],"image_ratios":["1.0000"],"tags":["hive-188262","neoxian","pimp","palnet","waivio","ctp","lassecash","creativecoin","proofofbrain","cent","lern","ecency","ecency"],"thumbnails":["https://images.ecency.com/DQmT6JB3C3LGfDXWnuMYuCcVFdknKbXrywUQakGHfKnuYzC/image.png"]}"
created2024-06-01 23:52:45
last_update2024-06-02 15:02:51
depth0
children4
last_payout2024-06-08 23:52:45
cashout_time1969-12-31 23:59:59
total_payout_value0.444 HBD
curator_payout_value0.440 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,736
author_reputation40,634,639,847,637
root_title"Basic Calculator - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,131,583
net_rshares2,114,422,048,599
author_curate_reward""
vote details (31)
@arc7icwolf ·
Something I can understand, finally! Ahahah

Curated by @arc7icwolf.byte for the #LearnToCode community.
properties (22)
authorarc7icwolf
permlinkre-paulmoon410-202465t14610130z
categoryhive-188262
json_metadata{"tags":["hive-188262","neoxian","pimp","palnet","waivio","ctp","lassecash","creativecoin","proofofbrain","cent","lern","ecency","ecency"],"app":"ecency/3.2.0-vision","format":"markdown+html"}
created2024-06-05 12:06:12
last_update2024-06-05 12:06:12
depth1
children1
last_payout2024-06-12 12:06:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length104
author_reputation504,569,010,043,585
root_title"Basic Calculator - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,224,374
net_rshares0
@paulmoon410 ·
After using what I know the other code is way simpler when you use all of Hives APIs.
properties (22)
authorpaulmoon410
permlinkre-arc7icwolf-202465t214348725z
categoryhive-188262
json_metadata{"type":"comment","tags":["hive-188262","neoxian","pimp","palnet","waivio","ctp","lassecash","creativecoin","proofofbrain","cent","lern","ecency","ecency"],"app":"ecency/3.1.2-mobile","format":"markdown+html"}
created2024-06-06 01:43:48
last_update2024-06-06 01:43:48
depth2
children0
last_payout2024-06-13 01:43:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation40,634,639,847,637
root_title"Basic Calculator - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,267,342
net_rshares0
@ironshield ·
Keep up the good work!
properties (22)
authorironshield
permlinkre-paulmoon410-202461t222255293z
categoryhive-188262
json_metadata{"tags":["hive-188262","neoxian","pimp","palnet","waivio","ctp","lassecash","creativecoin","proofofbrain","cent","lern","ecency"],"app":"ecency/3.2.0-vision","format":"markdown+html"}
created2024-06-02 02:23:06
last_update2024-06-02 02:23:06
depth1
children0
last_payout2024-06-09 02:23:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length22
author_reputation648,787,896,432,262
root_title"Basic Calculator - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,133,427
net_rshares0
@ironshield ·
!WINE
properties (22)
authorironshield
permlinkre-paulmoon410-202461t222317z
categoryhive-188262
json_metadata{"tags":["hive-188262","neoxian","pimp","palnet","waivio","ctp","lassecash","creativecoin","proofofbrain","cent","lern","ecency"],"app":"ecency/3.2.0-vision","format":"markdown+html"}
created2024-06-02 02:23:12
last_update2024-06-02 02:23:12
depth1
children0
last_payout2024-06-09 02:23:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation648,787,896,432,262
root_title"Basic Calculator - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,133,429
net_rshares0