1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 | #!/usr/bin/env python
#Datos del programa:
#Programa: Calculadora.
#Funcion: Realiza diversas operaciones entre dos numeros.
#Autor: Eodos.
#Fecha: 21 Febrero 2009.
#Introduccion
print "Calculadora"
operacion= ""
#Condicional de salida
while operacion!=7:
#Entrada de datos
numero1=float(raw_input("Escribe un numero: "))
numero2=float(raw_input("Escribe otro numero: "))
#Operaciones
print "1. Suma"
print "2. Resta"
print "3. Division"
print "4. Multiplicacion"
print "5. Potencia"
print "6. Raiz cuadrada"
print "7. Salir"
#Entrada de operacion
operacion=float(raw_input("Operacion:(1,2,3...) "))
#Suma
if operacion==1:
suma=float(numero1)+float(numero2)
print str(suma)
#Resta
elif operacion==2:
print "1." ,str(numero1) ,"-" ,str(numero2)
print "2." ,str(numero2) ,"-" ,str(numero1)
tiporesta=int(raw_input("1 o 2: "))
if tiporesta==1:
resta=float(numero1)-float(numero2)
print str(resta)
elif tiporesta==2:
resta=float(numero2)-float(numero1)
print str(resta)
#Division
elif operacion==3:
print "1." ,str(numero1) ,"entre" ,str(numero2)
print "2." ,str(numero2) ,"entre" ,str(numero1)
tipodivision=int(raw_input("1 o 2: "))
if tipodivision==1:
if numero2==0:
print "No puedes dividir entre 0"
else:
division=float(numero1)/float(numero2)
print str(division)
elif tipodivision==2:
if numero1==0:
print "No puedes dividir entre 0"
else:
division=float(numero2)/float(numero1)
print str(division)
#Multiplicacion
elif operacion==4:
multiplicacion=float(numero1)*float(numero2)
print str(multiplicacion)
#Potencia
elif operacion==5:
print "1." ,str(numero1) ,"elevado a" ,str(numero2)
print "2." ,str(numero2) ,"elevado a" ,str(numero1)
tipopotencia=int(raw_input("1 o 2: "))
if tipopotencia==1:
potencia=float(numero1)**float(numero2)
print str(potencia)
elif tipopotencia==2:
potencia=float(numero2)**float(numero1)
print str(potencia)
#Raiz cuadrada
elif operacion==6:
print "1. Raiz cuadrada de" ,str(numero1)
print "2. Raiz cuadrada de" ,str(numero2)
print "3. Raiz cuadrada de" ,str(numero1) ,"mas raiz cuadrada de" ,str(numero2)
print "4. Raiz cuadrada de" ,str(numero1) ,"+" ,str(numero2)
tiporaiz=int(raw_input("1, 2, 3 o 4: "))
if tiporaiz==1:
if numero1<0:
print "La raiz no tiene soluciones reales"
else:
raiz=float(numero1)**0.5
print str(raiz)
elif tiporaiz==2:
if numero2<0:
print "La raiz no tiene soluciones reales"
else:
raiz=float(numero2)**0.5
print str(raiz)
elif tiporaiz==3:
if numero1:
print "La raiz no tiene soluciones reales"
else:
raiz1=float(numero1)**0.5
raiz2=float(numero2)**0.5
raiz=float(raiz1)+float(raiz2)
print str(raiz)
elif tiporaiz==4:
sumaraiz=float(numero1)+float(numero2)
if sumaraiz<0:
print "La raiz no tiene soluciones reales"
else:
raiz=float(sumaraiz)**0.5
print str(raiz)
if operacion==7:
print "Gracias por usar el programa"
raw_input()
|