Skip to main content

how to make a calculator use python


 # This function adds two numbers

def add(x, y):
    return x + y

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

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

# This function 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:
    # take 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")

Comments

Popular posts from this blog

Prothom Alo website receives warning from “ethical hacker”

https://www.cpmrevenuegate.com/q0jty5uncq?key=a35f4908b5dde46d40f25ac14440afe1  Prothom Alo's website was hacked by apparently an ethical hacker on September 9 morning around 11 am. Although the website's functionality has not been affected, a message was seen pinned on the landing page of the website. At the time of writing, the message is no longer visible. The message, which was addressed to Matiur Rahman, Editor and Publisher of Prothom Alo, as well as the staff of the daily, began by saying: "I am not your enemy nor do I have any intention to damage any property of Prothom Alo." The message then went on to say to Prothom Alo: "the content management system (CMS) developed by Quintype Technologies India Ltd. that is used by your website to disseminate news online has critical security flaws." It then went on to explain that by using this CMS, "any person or organisation with malicious intentions can change, modify or modify any news or information p...

ফাতিমা তাসনিম আমার পরিবারের কেউ নন: উপদেষ্টা নাহিদ

 ফলো করুন খবরটি সঠিক নয় বলে রিউমার স্ক্যানার জানিয়েছে  খবরটি সঠিক নয় বলে রিউমার স্ক্যানার জানিয়েছেছবি: সংগৃহীত ফাতিমা তাসনিম নামের এক নারী কানাডায় বাংলাদেশ হাইকমিশনে মিথিলা ফারজানার পদে চাকরি পেয়েছেন বলে একটি খবর প্রকাশিত হয়েছে। তাতে ওই নারীর পরিচয় হিসেবে তথ্যপ্রযুক্তি উপদেষ্টা নাহিদ ইসলামের বোন বলা হয়েছে। খবরটি সঠিক নয় বলে জানিয়েছেন নাহিদ ইসলাম। ফ্যাক্ট চেকিং বা তথ্য যাচাইকারী প্রতিষ্ঠান রিউমার স্ক্যানারও একে ভুয়া খবর বলে জানিয়েছে। https://upodaitie.net/4/8090065 এ বিষয়ে আজ মঙ্গলবার রাতে নাহিদ ইসলাম বলেন, ‘ফাতিমা তাসনিম নামের এই নারী আমার পরিবারের কেউ নন। তিনি কোথায় নিয়োগ পেয়েছেন, তা আমি জানি না। তাঁর সঙ্গে আমার কোনো যোগাযোগও নেই। তিনি মূলত গণ–অধিকার পরিষদের নেত্রী।’এদিকে খবরটি যাচাই করে রিউমার স্ক্যানার বলেছে, বিডিপ্যানারোমা নামের এই ভুঁইফোড় সাইটটিতে বর্তমানে মাত্র চারটি নিউজ রয়েছে। এর একটি ফাতিমা তাসনিমকে নিয়ে। ফাতিমা তাসনিম গণ অধিকার পরিষদের উচ্চতর পরিষদের সদস্য। তাঁকে উপদেষ্টা নাহিদের বোন বলে দাবি করা হলেও আদতে তাঁদের মধ্যে কোনো সম্পর্ক নেই। ফাতিমা কানাডার বাংলাদেশ মিশ...
https://www.effectiveratecpm.com/ic3bxc2h7?key=7daf2971028e38498139c0342ffe7f6c