dimanche 20 septembre 2020

How do I ask for an input within an IF statement?

I'm a beginner so sorry if my code looks messy. I'm trying to make a code that asks if you want to count the Perimeter OR the Area of a Triangle OR a Square, just can't figure out the best way to attach q1 and q2.

Preferably the code would print the chosen way of calculating and also would change the "x" variable to 1 if you have chosen the Area of a Square or change it to 2 if you have chosen the Perimeter of a Square etc.

Feel free to give any coding tips.

q1 = input("Type 1 for Square, type 2 for Triangle."))

if q1 == "1":
    q2 = input("Type 1 for Area, Type 2 for Perimeter."))
      if q2 == "1":
        print("Calculating the Area of a Square.")
        x = 1
      else:
        print("Calculating the Perimeter of a Square.")
        x = 2

else:
    q2 = input("Type 1 for Area, Type 2 for Perimeter."))
      if q2 == "1":
        print("Calculating the Area of a Triangle.")
        x = 3
      else:
        print("Calculating the Perimeter of a Triangle.")
        x = 4

Aucun commentaire:

Enregistrer un commentaire