lundi 31 août 2020

Can I disregard certain code when certain input is given?

I am building a basic calculator on python to get to know the basics of programming and what not. Basically my issue is that when I am squaring a number with my calculator it will still ask for my second number, while it spits out the correct answer still I would like it to not ask for my second number when the square function is used.

name = input("Enter your name: ")
lastname = input("Enter your last name: ")
print("Welome " + name + " " + lastname + "!")
num1 = float(input("Enter a number to calculate: "))
Component = input("*, /, +, -...?????: ")
num2 = float(input("Enter your last number...: "))
if Component == "*":
    print(num1 * num2)
if Component == "+":
    print(num1 + num2)
if Component == "/":
    print(num1 / num2)
if Component == "-":
    print(num1 - num2)
if Component == "sqr":
    print(num1 ** 2)
    

Aucun commentaire:

Enregistrer un commentaire