Switch case Python, no corre que falta? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Switch case Python, no corre que falta?

opcion = int(input("Menu \n -----------\n \t"+"1. Cuadrado \n \t2. Triangulo \n \t3. Circulo \n \t4. Romboide \n \t5. Rombo \n \t6. Trapecio \n \t "+"POR FAVOR INGRESE LA OPCION QUE DESEE:")); ifĀ  ( opcion == 1): X= float(input('ingrese lado ')) A= X**2 print (A) Ā # cuadrado elif (opcion == 2): b= float(input('ingrese base ')) h = float(input('ingrese Altura ')) Area= b*h/2 print (Area) Ā # triangulo elif (opcion == 3): Ļ€ = 3.14 R = float(input('ingrese Radio ')) Are = Ļ€*R**2 print (Are) Ā # circulo elif (opcion == 4): base1= float(input('ingrese base ')) haltura = float(input('ingrese Altura ')) areaaa = base1*haltura print (areaaa) Ā #romboide elif (opcion == 5): D = float(input('ingrese Diagonal Mayor ')) d = float(input('ingrese Diagonal Menor ')) AREA= D*d/2 print (AREA) Ā #rombo elif (opcion == 6): X = float(input('ingrese base mayor ')) Y = float(input('ingrese base menor ')) Z = float(input('ingrese altura ')) A= (X+Y)*Z/2 print (A) Ā #trapecio e

15th Dec 2018, 10:28 AM
Jeisson Camilo RincĆ³n
Jeisson Camilo RincĆ³n - avatar
2 Respostas
+ 1
J'espĆØre que tue comprends mauvais francais. Il n'y a pas de switch statement, mais on peut utiliser une dict (there is no switch statement, but you can use a dict instead): def cuadrado(): X = float(input('ingrese lado')) A = X**2 print(A) def triangulo(): b = float(input('ingrese base ')) h = float(input('ingrese Altura ')) Area= b*h/2 # etc. options = {1: 'cuadrado', 2: 'triangulo'} # etc. c = int(input('What do you want to calculate? [1) cuadrado, 2) triangulo]')) # etc. exec(options[c] + '()')
15th Dec 2018, 11:57 AM
Anna
Anna - avatar
0
Jeisson Camilo RincĆ³n , match case Python 3.10 šŸ˜Ž Sololearn uses Python 3.9.16 šŸ˜­ https://peps.python.org/pep-0636/
14th Nov 2023, 2:16 AM
Rain
Rain - avatar