lunes, 8 de octubre de 2018

Menu poligonos



  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
122
123
from Tkinter import *


def funcion(select, poligonos):
    ventana = Toplevel()
    ventana.configure(bg="gray")
    ventana.title(Menu poligonos)
    if select == 1:
        panel = Canvas(ventana,width=300, height=300, bg='light blue')
        panel.pack()
        panel.create_polygon(20, 20, 20, 40, 50, 40, 50, 70, 30, 70, 30, 80, 20, 80,
                             20, 100, 50, 100, 80, 90, 100, 90, 110, 100, 130, 100,
                             140, 90, 160, 90, 170, 100, 180, 100, 180, 110, 200, 110,
                             190, 100, 190, 60, 200, 60, 200, 50, 150, 50, 150, 40,
                             160, 40, 160, 30, 130, 30, 130, 40, 140, 40, 140, 50,
                             100, 50, 100, 20, fill='brown', outline='white')
        # rueda1
        panel.create_oval(60, 90, 110, 120, fill='black', outline='black')
        # rueda2
        panel.create_oval(120, 90, 170, 120, fill='black', outline='black')
        # ventana
        panel.create_rectangle(60, 40, 80, 60, fill='black', outline='black')
        # humo
        panel.create_oval(140, 10, 150, 20, fill='black', outline='black')

        # humo2
        panel.create_oval(120, 10, 130, 20, fill='black', outline='black')

        # humo2
        panel.create_oval(110, 10, 120, 20, fill='black', outline='black')


    elif select == 2:
        panel = Canvas(ventana,width=1400, height=1400, bg='light blue')

        # Cuadrado grande
        panel.create_rectangle(300, 200, 800, 600, fill='black', outline='black')
        # ventana 1
        panel.create_rectangle(300, 200, 500, 400, fill='white', outline='black')
        # ventan 2
        panel.create_rectangle(600, 200, 800, 400, fill='white', outline='black')
        # puerta
        panel.create_rectangle(500, 500, 600, 600, fill='red', outline='black')

        # Trapecio techo
        panel.create_polygon(300, 200, 800, 200, 700, 100, 400, 100, fill='blue', outline='black')

        # Pino
        panel.create_polygon(1000, 500, 1300, 500, 1150, 200, fill='green', outline='black')
        # tronco
        panel.create_rectangle(1100, 500, 1200, 600, fill='brown', outline='black')

        panel.pack()
    elif select == 3:
        pack = Canvas(ventana, width=150, height=180, bg="steelblue")

        # Gorra de Mario
        pack.create_polygon(40, 10, 90, 10, 90, 20, 120, 20, 120, 30, 30, 30,
                              30, 20, 40, 20, width=2, fill="RED", outline="BLACK")
        # Cabeza de Mario
        pack.create_polygon(30, 30, 100, 30, 100, 40, 120, 40, 120, 50, 130, 50,
                              130, 60, 120, 60, 120, 70, 110, 70, 110, 80, 40, 80,
                              40, 70, 20, 70, 20, 40, 30, 40, width=2,
                              fill="DARKORANGE", outline="BLACK")
        # Cuerpo de Mario
        pack.create_polygon(30, 80, 90, 80, 90, 90, 120, 90, 120, 100, 130, 100,
                              130, 110, 110, 110, 110, 120, 100, 120, 100, 130,
                              110, 130, 110, 150, 80, 150, 80, 140, 60, 140, 60, 150,
                              30, 150, 30, 130, 40, 130, 40, 120, 30, 120, 30, 110,
                              10, 110, 10, 100, 20, 100, 20, 90, 30, 90, width=2,
                              fill="SaddleBROWN", outline="BLACK")
        # Ropa de Mario
        pack.create_polygon(50, 80, 60, 80, 60, 100, 80, 100, 80, 90, 90,
                              90, 90, 110, 100, 110, 100, 130, 110, 130,
                              110, 150, 80, 150, 80, 140, 60, 140, 60, 150,
                              30, 150, 30, 130, 40, 130, 40, 110, 50, 110,
                              width=2, fill="RED", outline="BLACK")
        # Mano Izquierda de Mario
        pack.create_polygon(10, 110, 30, 110, 30, 120, 40, 120, 40, 130, 30, 130,
                              30, 140, 10, 140, width=2, fill="orange", outline="BLACK")
        # Mano Derecha de Mario
        pack.create_polygon(130, 110, 130, 140, 110, 140, 110, 130, 100, 130,
                              100, 120, 110, 120, 110, 110, width=2, fill="orange", outline="BLACK")
        # Bota Izquierda de Mario
        pack.create_polygon(50, 150, 50, 170, 10, 170, 10, 160,
                              20, 160, 20, 150, width=2, fill="saddlebrown", outline="BLACK")
        # Bota Derecha de Mario
        pack.create_polygon(100, 150, 100, 170, 140, 170, 140, 160,
                              130, 160, 130, 150, width=2, fill="saddlebrown", outline="BLACK")
        # Boton Izquierdo
        pack.create_rectangle(80, 110, 90, 120, width=2, fill="yellow", outline="BLACK")
        # Boton Derecho
        pack.create_rectangle(50, 110, 60, 120, width=2, fill="yellow", outline="BLACK")
        # Ojo y Bigote
        pack.create_polygon(80, 70, 120, 70, 120, 60, 100, 60, 100, 50,
                              90, 50, 90, 30, 80, 30, 80, 50, 90, 50, 90, 60,
                              80, 60, width=2, fill="saddlebrown", outline="black")
        # Cabello
        pack.create_polygon(30, 40, 20, 40, 20, 70, 40, 70, 40, 60, 30, 60,
                              30, 30, 60, 30, 60, 40, 50, 40, 50, 50, 60, 50,
                              60, 60, 40, 60, 40, 40, width=2, fill="saddlebrown", outline="black")
        pack.pack()


def funcion2():
    vent = Tk()
    vent.geometry("300x150")
    vent.configure(bg="black")
    vent.title("Poligonos")
    boton1 = Button(vent, text="Tren", bg="red", fg="blue", command=lambda: funcion(1, ''))
    boton1.pack(padx=5, pady=5, fill=X)
    boton2 = Button(vent, text="casita", bg="red", fg="blue", command=lambda: funcion(2, ''))
    boton2.pack(padx=5, pady=5, fill=X)
    boton3 = Button(vent, text="Mario bros", bg="red", fg="blue", command=lambda: funcion(3,''))
    boton3.pack(padx=5, pady=5, fill=X)




    vent.mainloop()


funcion2()

Menu Registros Tarea


 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
def menu():
    print "Menu\n\n 1).-Capturar nuevo registro\n 2).-Mostrar archivo\n 3).-Eliminar registros\n 4).-Salir\n"

    while True:
        opc = raw_input("Dame la opcion")
        if opc =='1':
            print "Nuevo registro\n"
            archivo = open("ejemplo.csv", "a")
            nombre = raw_input("Dame nombre: ")
            apellido = raw_input("Dame apellido: ")
            print "Se ha capturado: " + nombre + " con el apellido: " + apellido
            archivo.write(nombre + "," + apellido + "\n")

        elif opc == '2':
            print "Mostrar registros\n"
            archivo = open("ejemplo.csv")
            print(archivo.read())
            archivo.close()

        elif opc=='3':
            archivo = open("ejemplo.csv", "a")
            archivo.truncate()
            print "Registros Eliminados"
            archivo.close()

        elif opc == '4':
            print'adios'
            break

menu()

domingo, 7 de octubre de 2018

Menu Registros



 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
print  '       MENU\n\n 1).- Capturar Nuevo Registro\n 2).- Mostrar Registros\n 3).- Eliminar Registros'
opcion= raw_input('Dame la opcion:')

if opcion == '1':
    print'Nuevo registro\n'
    archivo = open('ejemplo.csv','a')

    nombre = raw_input('Ingrese el nombre: ')
    apellido = raw_input('Ingrese el apellido: ')

    print'Se ha capturado: ' + nombre + ' con el apellido '+ apellido
    archivo.write('\n'+nombre + ',' + apellido)

elif opcion=='2':
    print 'Mostrar Registro\n'
    archivo=open('ejemplo.csv')
    print(archivo.read())

    archivo.close()

elif opcion=='3':
    print 'Eliminar Registro'
    archivo = open('ejemplo.csv','a')
    archivo.truncate()
    print'Registros Eliminados'
    archivo.close()

else:
    print'Debes seleccionar una opcion valida del MENU'

martes, 2 de octubre de 2018

Numero impar


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def sacaimpar(numeroin,numerofin):
    i=numeroin
    for i in range(numeroin,numerofin+1):
        residuo=numeroin%2
        if residuo!=0:
            print'el numero es impar: ',numeroin
        else:
            print'el nuemro es par: ',numeroin
        numeroin=numeroin+1




numeroin = int(input('dame numero inicial: '))
numerofin = int(input('dame numero final:'))
sacaimpar(numeroin,numerofin)

Pide numeros


 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
def cuentanum(numeroin,numerofin):
    cuentan = 0
    sumapar=0
    cuentapar=0
    while numeroin <= numerofin:
        print numeroin
        numeroin = numeroin + 1
        cuentan = cuentan + 1
        residuo=numeroin%2
        if residuo==0:
            sumapar=sumapar+numeroin
            cuentapar=cuentapar+1

    print'total de la suma de numeros pares',sumapar
    print 'total de numeros', cuentan
    print'los numeros pares son',cuentapar

def evaluar(numeroin,numerofin):
    if numeroin<=numerofin:
        cuentanum(numeroin,numerofin)
    else:
        print'no puede ser mayor que numero inicial'

numeroin=int(input('dame el numero inicial: '))
numerofin=int(input('dame el numero final: '))

evaluar(numeroin,numerofin)

Suma impar


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def sumaimpar(n,h):
    for i in range(h,n+1):
        if n%2 !=0:
            print n,
            h +=n
        n -=1

    print'su suma es: %i'%h

h = int(input('dame numero inicial: '))
n = int(input('dame numero final:'))
sumaimpar(n,h)

suma de numeros


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def sacarsuma(numeroin,numerofin):
    suma=0
    while numeroin<=numerofin:
        suma=suma+numeroin
        numeroin=numeroin+1

    print'la suma es: ',suma


numeroin = int(input('dame numero inicial: '))
numerofin = int(input('dame numero final:'))
sacarsuma(numeroin,numerofin)

Suma de producto


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
def sacarprod(numeroin,numerofin):
    mult=1
    while numeroin<=numerofin:
        mult=mult*numeroin
        numeroin=numeroin+1

    print'el producto es: ',mult





numeroin = int(input('dame numero inicial: '))
numerofin = int(input('dame numero final:'))
sacarprod(numeroin,numerofin)

uso de if


 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
import math

def menu():

    opc=1

    while opc !=0:
        print'1.- sacar numero par o impar'
        print'2.- sacar seno y coseno de dos numeros'
        print'3.- sacar logaritmo de un numero'
        print'4.- salir'
        opc=int(input('dame la opcion'))

        if opc == 1:

            numero=int(input('dame un numero---->'))
            resiudo = numero % 2
            if resiudo!=0:
                print'el numero es impar'

            else:

               print'el numero es par'

        elif opc == 2:
            seno =int(input('numero a sacar seno---->'))
            coseno= int(input('numero a sacar coseno---->'))
            resseno=math.sin(seno)
            rescoseno=math.cos(coseno)
            print'el resultado de seno',resseno
            print'el resultado de coseno',rescoseno

        elif opc ==3:
            lognum=int(input('dame el valor para el logaritmo'))
            lognum1=math.log10(lognum)
            print'el logaritmo es',lognum

        else:
            print'1.-si desea salir. 2.- si desea ir al menu'
            opc==int(input())
            if opc==1:
                print'adios del menu'
                opc=0

            else:
                opc2=1




menu()
print 'adios'

Poligono




 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
from Tkinter import *

ventana = Tk()
ventana.title('hace un tren')
ventana.config(bg='black')
ventana.geometry('500x500')


def tren(ventana):
    panel = Canvas(width=300, height=300, bg='light blue')
    panel.create_polygon(20,20,20,40,50,40,50,70,30,70,30,80,20,80,
                         20,100,50,100,80,90,100,90,110,100,130,100,
                         140,90,160,90,170,100,180,100,180,110,200,110,
                         190,100,190,60,200,60,200,50,150,50,150,40,
                         160,40,160,30,130,30,130,40,140,40,140,50,
                         100,50,100,20,fill='brown', outline='white')
    #rueda1
    panel.create_oval(60,90,110,120,fill='black', outline='black')
    #rueda2
    panel.create_oval(120, 90, 170, 120, fill='black', outline='black')
    #ventana
    panel.create_rectangle(60, 40, 80, 60, fill='black', outline='black')
    #humo
    panel.create_oval(140,10,150,20,fill='black', outline='black')

    # humo2
    panel.create_oval(120, 10, 130, 20, fill='black', outline='black')

    # humo2
    panel.create_oval(110, 10, 120, 20, fill='black', outline='black')

    panel.pack()



boton = Button(ventana,text='hace un tren', command = lambda:tren(ventana))
boton.pack()
ventana.mainloop()