First Python Program

while “True”:

print (“CALCULATOR”)
print (“Select Operation:”)
print (“1. Add”)
print (“2. Subtract”)
print (“3. Multiplication”)
print (“4. Division”)
print (“5. Modulus”)
print (“6. Exponentiate”)

choice = input…


This content originally appeared on DEV Community and was authored by Mani Prabhu

while "True":

    print ("CALCULATOR")
    print ("Select Operation:")
    print ("1. Add")
    print ("2. Subtract")
    print ("3. Multiplication")
    print ("4. Division")
    print ("5. Modulus")
    print ("6. Exponentiate")

    choice = input("Enter Choice (1/2/3/4/5/6/7): ")

    if choice == "7":
       print ("Thank you for using calculator")

    elif choice < "7":

         num1 = float(input("Enter First Number:"))
         num2 = float(input("Enter Second Number:"))

    elif choice > "7":
         print ("Invalid Choice")

    # Addition

    if choice == "1":
       result = num1 + num2
       print ("result is: ", result)

    # Subtraction

    elif choice == "2":

       result = num1 - num2
       print ("result is: ", result)

    #Multiplication

    elif choice == "3":
       result = num1 * num2
       print ("result is: ", result)

    # Division


    elif choice == "4":
       result = num1 / num2
       print ("result is: ", result)
    # Remainder

    elif choice == "5":
       result = num1 % num2
       print ("result is: ", result)


    elif choice == "6":
       result = num1 ** num2
       print ("result is: ", result)


This content originally appeared on DEV Community and was authored by Mani Prabhu


Print Share Comment Cite Upload Translate Updates
APA

Mani Prabhu | Sciencx (2024-07-16T03:27:11+00:00) First Python Program. Retrieved from https://www.scien.cx/2024/07/16/first-python-program/

MLA
" » First Python Program." Mani Prabhu | Sciencx - Tuesday July 16, 2024, https://www.scien.cx/2024/07/16/first-python-program/
HARVARD
Mani Prabhu | Sciencx Tuesday July 16, 2024 » First Python Program., viewed ,<https://www.scien.cx/2024/07/16/first-python-program/>
VANCOUVER
Mani Prabhu | Sciencx - » First Python Program. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/16/first-python-program/
CHICAGO
" » First Python Program." Mani Prabhu | Sciencx - Accessed . https://www.scien.cx/2024/07/16/first-python-program/
IEEE
" » First Python Program." Mani Prabhu | Sciencx [Online]. Available: https://www.scien.cx/2024/07/16/first-python-program/. [Accessed: ]
rf:citation
» First Python Program | Mani Prabhu | Sciencx | https://www.scien.cx/2024/07/16/first-python-program/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.