Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/12/2010, 12:07
Avatar de ARICARRARO
ARICARRARO
 
Fecha de Ingreso: diciembre-2010
Ubicación: México
Mensajes: 227
Antigüedad: 13 años, 4 meses
Puntos: 10
Programando en Python...1era parte

Estrenando mi blog en este sitio.

Aqui les dejó varios programitas hechos en Python. Espero les sirvan

1. Determinar el número mayor,central y menor de tres números:
#Autor: CARRARO
print "Introduce tres números (solo positivos y no iguales entre si)"
a=0
b=0
c=0
mayor=0
central=0
menor=0
while a<=0:
a=int(raw_input('Introduce no.1:'))
while b<=0 or b==a:
b=int(raw_input('Introduce no.2:'))
while c<=0 or c==b or c==a:
c=int(raw_input('Introduce no.3:'))
#1
if a<b and a<c:
if c>a and c>b:
central=b
mayor=c
menor=a
#2
if a<b and a<c:
if b>a and b>c:
central=c
mayor=b
menor=a
#3
if b<a and b<c:
if c>a and c>b:
central=a
mayor=c
menor=b
#4
if b>a and b>c:
if c<a and c<b:
central=a
mayor=b
menor=c
#5
if a>b and a>c:
if c<a and c<b:
central=b
mayor=a
menor=c
#6
if a>b and a>c:
if b<a and b<c:
central=c
mayor=a
menor=b
print "Mayor: ",mayor,"Central: ",central,"Menor: ",menor

2. Menú
from math import pi
def VerMenu():
print "\tCálculo de áreas"
print "\t1. Rectángulo"
print "\t2. Circulo"
print "\t3. Triángulo"
print "\t4. Salir"
opc=int(raw_input('Tu opción es:'))
return opc
#opcion='s'
#while opcion!='n':
#entrada=int(raw_input('Tu opción es:'))
entrada=VerMenu()
if entrada ==1:
base=float(raw_input('Base:'))
altura=float(raw_input('Altura:'))
area=base*altura
print "El resultado: ",area
VerMenu()
elif entrada==2:
radio=float(raw_input('Radio:'))
area=pi*pow(radio,2)
print "El resultado: ",area
VerMenu()
elif entrada==3:
base=float(raw_input('Base:'))
altura=float(raw_input('Altura:'))
area=(base*altura)/2
print "El resultado: ",area
VerMenu()
elif entrada==4:
exit()
else:
print "Opción fuera de rango"
#VerMenu()
#opcion=raw_input('¿Desea salir de la aplicación?')
print "Fin"

3. Mayor de 3 números sin función
#Autor:CARRARO 2010
a,b,c,mayor=0,0,0,0
print "Mayor de tres números (sin función)"
while a<=0:
a=int(raw_input('Valor de no.1:'))
while b<=0 or b==a:
b=int(raw_input('Valor de no.2:'))
while c<=0 or c==b or c==a:
c=int(raw_input('Valor de no.3:'))
mayor=a
if b>mayor:
mayor=b
if c>mayor:
mayor=c
print "El mayor es: ",mayor

4. Mayor de 3 números con función
#Autor:CARRARO 2010
def DeterminaMayor(a,b,c):
mayor=a
if b>mayor:
mayor=b
return mayor
if c>mayor:
mayor=c
return mayor
a,b,c,Vermayor=0,0,0,0
print "Mayor de tres números (con función)"
while a<=0:
a=int(raw_input('Valor de no.1:'))
while b<=0 or b==a:
b=int(raw_input('Valor de no.2:'))
while c<=0 or c==b or c==a:
c=int(raw_input('Valor de no.3:'))
Vermayor=DeterminaMayor(a,b,c)
print "El mayor es: ",Vermayor

5. POO en Python
#Autor: CARRARO 2010
class Calculos:
def asignaVf(self,vf):
self.vf=vf
def asignaVi(self,vi):
self.vi=vi
def asignaT(self,t):
self.t=t
def obtenerVf(self):
return vf
def obtenerVi(self):
return vi
def obtenerT(self):
return t
def CalcAcel(self):
return (self.vf - self.vi)/self.t
#MAIN
a=0
t=0
vi=0
vf=0
print "Cálculo de la aceleración"
while vi<=0:
vi=float(raw_input('Velocidad inicial:'))
while vf<=0:
vf=float(raw_input('Velocidad final:'))
while t<=0:
t=float(raw_input('Tiempo:'))
miObjeto=Calculos()
miObjeto.asignaVf(vf)
miObjeto.asignaVi(vi)
miObjeto.asignaT(t)
miObjeto.obtenerVf()
miObjeto.obtenerVi()
miObjeto.obtenerT()
print "Aceleración obtenida %f"% miObjeto.CalcAcel()
print "fin,funciona correctamente"

Son muy simples, pero funcionan.