-3
I wanted a way that when the user typed the key = 4, all the conditions I assigned were printed, have some mode or I would have to assign an if condition and repeat everything again?
import math
import sys
print()
print("#" * 51)
print("Este programa calculará o SENO, COSSENO e TANGENTE.")
print("#" * 51)
print()
lista1 = [1,2,3,4,5]
a = int(input("Para realizar os cálculos digite: \n\nSENO = 1 \nCOSSENO = 2 \nTANGENTE = 3 \nTODOS = 4 \nENCERRAR PROGRAMA = 5 \n\nDigite a seguir: "))
print("#" * 51)
print()
while a not in lista1:
print("Ei, digite um dos números informados!")
print()
a = int(input("Para realizar os cálculos digite: \n\nSENO = 1 \nCOSSENO = 2 \nTANGENTE = 3 \nTODOS = 4 \nENCERRAR PROGRAMA = 5 \n\nDigite a seguir: "))
print("#" * 51)
print()
if a == 1:
co = float(input("Digite o valor do CATETO OPOSTO: "))
hi = float(input("Digite o valor da HIPOTENUSA: "))
print("#" * 51)
print()
sen = co / hi
print(f"O valor do SENO é igual à {round(sen, 3)}!")
print()
if a == 2:
ca = float(input("Digite o valor do CATETO ADJACENTE: "))
hi = float(input("Digite o valor da HIPOTENUSA: "))
print("#" * 51)
print()
cos = ca / hi
print(f"O valor do COSSENO é igual à {round(cos, 3)}!")
print()
if a == 3:
co = float(input("Digite o valor do CATETO OPOSTO: "))
ca = float(input("Digite o valor do CATETO ADJACENTE: "))
print("#" * 51)
print()
tan = co / ca
print(f"O valor da TANGENTE é igual à {round(tan, 3)}!")
print()
if a == 5:
print("Encerrando programa...")
print()
sys.exit(0)
#Quando o usuario digitasse a key 4 todos os cáculos seriam impressos
Separate the specific code portions into function and for each option call the function or related functions(s).
– Augusto Vasques
It wouldn’t be enough to add one
or
on your terms?if a == 1 or a == 4
, or more simplyif a in {1, 4}
– Woss
@Woss thanks friend, helped a lot, solved my problem
– Pedro Tigre
Ideally you would make a different logic for the same value 4, because if you call again from the previous ifs will ask the user to type values repeatedly.
– AmSs