B
bandcamp57
Hello, i'm making a calculator and I want to be able to use decimals but I don't like it when it comes out as ex.12.0 when it should be 12. I tried using .rstrip("0".rstrip(".") but that never seemed to work. If anyone has a solution please let me know, all help is greatly appreciated.
Code:
def Main():
print(" Welcome to the Calculator! What would you like to do?")
print("")
print("1) Basic Operations")
user_input = input("Enter the number corresponding with your choice: ")
if user_input == "1":
BasicOperations()
def BasicOperations():
def Add():
A = float(input("Enter the first number you want to add: "))
B = float(input("Enter the second number you want to add: "))
Answer = A+B
print("The sum of", A, "and", B, "is: ", Answer)
print("")
Main()
def Sub():
A = float(input("Enter the first number you want to subtract: "))
B = float(input("Enter the second number you want to subtract: "))
Answer = A-B
print("The difference between", A, "and", B, "is: ", Answer)
print("")
Main()
def Mul():
A = float(input("Enter the first number you want to multiply: "))
B = float(input("Enter the second number you want to multiply: "))
Answer = A*B
print("The product of", A, "and", B, "is: ", Answer)
print("")
Main()
def Div():
A = float(input("Enter the first number you want to divide: "))
B = float(input("Enter the second number you want to divide: "))
Answer = A/B
print("The quotient of", A, "and", B, "is: ", Answer)
print("")
Main()
print("You have selected Basic Operations.")
print("1) Addition")
print("2) Subtraction")
print("3) Multiplication")
print("4) Division")
print("")
choice = input("Select the number corresponding with your choice: ")
if choice == "1":
Add()
elif choice == "2":
Sub()
elif choice == "3":
Mul()
elif choice == "4":
Div()
Main()
Code:
def Main():
print(" Welcome to the Calculator! What would you like to do?")
print("")
print("1) Basic Operations")
user_input = input("Enter the number corresponding with your choice: ")
if user_input == "1":
BasicOperations()
def BasicOperations():
def Add():
A = float(input("Enter the first number you want to add: "))
B = float(input("Enter the second number you want to add: "))
Answer = A+B
print("The sum of", A, "and", B, "is: ", Answer)
print("")
Main()
def Sub():
A = float(input("Enter the first number you want to subtract: "))
B = float(input("Enter the second number you want to subtract: "))
Answer = A-B
print("The difference between", A, "and", B, "is: ", Answer)
print("")
Main()
def Mul():
A = float(input("Enter the first number you want to multiply: "))
B = float(input("Enter the second number you want to multiply: "))
Answer = A*B
print("The product of", A, "and", B, "is: ", Answer)
print("")
Main()
def Div():
A = float(input("Enter the first number you want to divide: "))
B = float(input("Enter the second number you want to divide: "))
Answer = A/B
print("The quotient of", A, "and", B, "is: ", Answer)
print("")
Main()
print("You have selected Basic Operations.")
print("1) Addition")
print("2) Subtraction")
print("3) Multiplication")
print("4) Division")
print("")
choice = input("Select the number corresponding with your choice: ")
if choice == "1":
Add()
elif choice == "2":
Sub()
elif choice == "3":
Mul()
elif choice == "4":
Div()
Main()