def order(l):
for i in range(0, len(l)):
if i > 0:
if l[i] > l[i-1]:
print(l[i])
l = [1, 2, 3, 4, 5, 6, 7]
order(l)
def insertion_sort(array):
for index in range(1, len(array)):
current_value = array[index]
position = index
while position > 0 and array[position - 1] > current_value:
array[position] = array[position - 1]
position -= 1
array[position] = current_value
return array
insertion_sort(["juan", "pablo", "caro"])
from tkinter import *
def calcular():
horas = int(horasTrabajadas.get())
tarifa = int(tarifaPorHora.get())
salario = horas * tarifa
Resultado['text'] = "Salario: $" + str(salario)
ventana = Tk()
ventana.title("Salario")
ventana.geometry("350x200")
ventana.configure(background="light blue")
horasTrabajadas = Entry(ventana)
horasTrabajadas.grid(column=1, row=1)
tarifaPorHora = Entry(ventana)
tarifaPorHora.grid(column=1, row=2)
etiqueta1 = Label(ventana, text="Ingresa horas trabajadas:")
etiqueta1.grid(column=0, row=0)
etiqueta2 = Label(ventana, text="Ingresa tarifa por hora:")
etiqueta2.grid(column=
def main():
mainWindow = tkinter.Tk()
mainWindow.geometry("{}x{}".format(400, 200))
mainWindow.title("Empleado")
lbHoras = tkinter.Label(mainWindow, text="Ingrese las horas laboradas: ")
lbHoras.grid(row=0, column=0)
lbTarifa = tkinter.Label(mainWindow, text="Ingrese la tarifa por hora: ")
lbTarifa.grid(row=1, column=0)
lbSalario = tkinter.Label(mainWindow, text="Salario a pagar: ")
lbSalario.grid(row=2, column=0)
txtHoras = tkinter.Entry(mainWindow)
txtHoras.grid(row=0, column=1)
txtTarifa = tkinter.Entry(mainWindow)
txtTarifa.grid(row=1, column=1)
txtSalario =
names = ['Mary', 'Isla', 'Sam']
names = sorted(names, key=lambda name: name[-1])
def ordenamiento(lista):
n = len(lista)
for i in range(n):
for j in range(0, n - i - 1):
if lista[j] > lista[j + 1]:
lista[j], lista[j + 1] = lista[j + 1], lista[j]
lista = [12,11,10,9,8,7,6,5,4,3,2,1]
ordenamiento(lista)
print(lista)
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
nombres = ['carlos', 'sara', 'diana', 'camilo', 'pedro', 'alexandra', 'andres', 'juan', 'julian', 'felipe', 'maria', 'camila', 'laura', 'lorenzo', 'francisco']
for i in range(len(nombres)):
for j in range(len(nombres)):
if nombres[i] < nombres[j]:
nombres[i],nombres[j] = nombres[j],nombres[i]
print(nombres)
sms = "Cad@dn@ @n@jnC@ @nd@C@jn@n@dn@n@ @j@ @dnC@n@jn@n@jC@@n@ @n@jnC@dn@nC@ @j@ @dn@nC@jn@n@jC@j@ @dn@nC@jn@n@jC@j@ @j@ @dn@nC@jn@n@jC@j@ @j@ @dn@nC@jn@n@jC@j@ @j@ @dn@nC@jn@n@jC@j@ @j@ @dnC@jn@n@jC@j@ @j@ @dnC@jn@n@jC@j@ @j@ @dnC@jn@n@jC@j@ @j@ @dnC@jn@n@jC@j@ @j@ @dnC@jn@n@jC@j@ @j@ @dnC@jn@n
def suma(a, b):
return a + b
def resta(a, b):
return a - b
def multiplicacion(a, b):
return a * b
def division(a, b):
return a / b
print("Seleccione operación")
print("1) Suma")
print("2) Resta")
print("3) Multiplicación")
print("4) División")
opcion = input("Ingrese la opción (1/2/3/4):")
num1 = int(input("Ingrese primer número: "))
num2 = int(input("Ingrese segundo número: "))
if opcion == "1":
print(suma(num1, num2))
elif opcion == "2":
print(resta(num1, num2))
elif opcion == "3":
print(multiplicacion(num1, num2))
elif
def printMins(l):
if len(l) > 1:
for i in range(1, len(l)):
if (l[i] < l[i-1]):
print(l[i])
l = [1, 3, 4, 5, 6, 9, -1]
printMins(l)
def suma(a, b):
return a + b
def resta(a, b):
return a - b
def multiplicacion(a, b):
return a * b
def division(a, b):
return a / b
message = "r@@e@@v@@e@@r@@s@@e"
def decode(sms):
return sms.replace('@', '')[::-1]
print(decode(message))
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
# Take input from the user
choice = input("Enter choice(1/2/3/4):")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif
lista = [0.5, 0.1, 0.3, 0.3, 0.4, 0.2, 0.1, 0.1, 0.3, 0.1, 0.2]
for time in lista:
if lista.index(time) + 1 < len(lista):
if time > lista[lista.index(time) + 1]:
print(time)
def add(a, b):
return a + b
add(1, 2)
def add(a, b):
return a + b
def minus(a, b):
return a - b
def product(a, b):
return a * b
def division(a, b):
return a / b
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
# Take input from the user
choice = input("Enter choice(1/2/3/4): ")
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
el
def slow(l):
previous = 0
for v in l:
if v > previous:
print(v)
previous = v
slow([3, 5, 4, 7, 9, 10, 11, 2, 3])
def find_difference(list):
total_time = 0
for i in range(0, len(list)):
if i == 0:
total_time = list[i]
else:
if list[i] > list[i-1]:
print(f"{list[i]} is greater than {list[i-1]}. time {i} is {list[i]}")
total_time = list[i]
find_difference([1, 2, 3, 5, 8, 13, 21, 34])
def print_max(lista):
for i in range(len(lista) - 1):
if lista[i + 1] > lista[i]:
print(lista[i + 1])
print_max([1, 2, 3, 2, 4])
def insert_sort(lista):
n = len(lista)
for i in range(1, n):
key = lista[i]
j = i - 1
while j >= 0 and lista[j] > key:
lista[j + 1] = lista[j]
j -= 1
lista[j + 1] = key
return lista
insert_sort(lista)
def insertion_sort_names():
names = ["Juan", "Jose", "Ana", "Pablo", "Maria", "Jesus", "Carlos", "Pedro"]
for i in range(1, len(names)):
value_to_insert = names[i]
hole_position = i
while hole_position > 0 and names[hole_position - 1] > value_to_insert:
names[hole_position] = names[hole_position - 1]
hole_position = hole_position - 1
names[hole_position] = value_to_insert
return names
insertion_sort_names()
sms = "!@rodamargORP@oredadrev@nu@sere@is¡"
sms = sms.replace('@', '')
sms = sms[::-1]
print(sms)
lst = input("Ingrese la lista de participantes: ")
lst = lst.split(' ')
lst = [int(i) for i in lst]
for i in range(len(lst)):
for j in range(len(lst)-1):
if lst[j] > lst[j+1]:
lst[j], lst[j+1] = lst[j+1], lst[j]
print(lst)
def bubbleSort(list):
for i in range(len(list)):
for j in range(len(list) - i - 1):
if list[j] > list[j + 1]:
list[j], list[j + 1] = list[j + 1], list[j]
return list
list = [3, 2, 4, 1, 5]
bubbleSort(list)
def get_slower_times(times):
previous = times[0]
slower_times = []
for time in times[1:]:
if time > previous:
slower_times.append(time)
previous = time
return slower_times
from tkinter import *
import tkinter as tk
def total():
n1 = int(v1.get()) #v1 = variable para entre de datos
n2 = int(v2.get())
s = n1 * n2
v3.set(s) #v3 = variable para salida
print(s)
window = tk.Tk()
v1 = tk.IntVar()
v2 = tk.IntVar()
v3 = tk.IntVar()
l = Label(window, text="Horas laboradas:")
n1 = Entry(window, textvariable=v1)
l2 = Label(window, text="Tarifa por hora:")
n2 = Entry(window, textvariable=v2)
b = Button(window, text="Calcular", command=total)
l3 = Label(window, text="Salario:")
n3 = Entry(window, textvariable=v3)
l.pack()
n1.pack()
l
#include tkinter
def esto(a, b):
return a + b
esto(1, 2)
def insertionSort(lista):
print(lista)
for i in range (1, len(lista)):
j=i-1
while j>=0 and lista[j] > lista[j+1]:
lista[j], lista[j+1] = lista[j+1], lista[j]
j=j-1
print(lista)
return lista
insertionSort([2,4,5,1,3])
import taller_operaciones as taller
numero1 = int(input("Ingrese el primer numero : "))
numero2 = int(input("Ingrese el segundo numero : "))
operacion = input("Que operacion desea realizar (+,-,*,/): ")
if operacion == "+":
resultado = taller.suma(numero1, numero2)
print("El resultado de la suma es:", resultado)
elif operacion == "-":
resultado = taller.resta(numero1, numero2)
print("El resultado de la resta es:", resultado)
elif operacion == "*":
resultado = taller.multiplicacion(numero1, numero2)
print("El resultado de la multiplicacion es:", resultado)
elif operacion == "/":
resultado = taller.division(numero1, numero2)
print("El resultado de la division es:", resultado)
else:
def ordenamiento_por_insercion(lista):
for i in range(1,len(lista)):
val = lista[i]
j = i-1
while j >= 0 and val < lista[j] :
lista[j+1] = lista[j]
j -= 1
lista[j+1] = val
return lista
ordenamiento_por_insercion(["Luz", "Carlos", "Jose", "Anna"])
def insertionSort(array)
for step in range(1, len(array)):
key = array[step]
j = step-1
while j >= 0 and key < array[j] :
array[j + 1] = array[j]
j -= 1
array[j + 1] = key
array = [3, 5, 4, 6, 8, 1, 2, 12, 41, 25]
insertionSort(array)
print("Sorted array is:")
for i in range(len(array)):
print("% d" % array[i])
import taller_modulo
numero_1 = input("Ingrese el primer número: ")
numero_2 = input("Ingrese el segundo número: ")
operacion = input("Seleccionar la operación: \n1. Suma\n2. Resta\n3. Multiplicación\n4. División\n")
if operacion == "1":
print(taller_modulo.suma(numero_1, numero_2))
elif operacion == "2":
print(taller_modulo.resta(numero_1, numero_2))
elif operacion == "3":
print(taller_modulo.multiplicacion(numero_1, numero_2))
elif operacion == "4":
print(taller_modulo.division(numero_1, numero_2))
a=input('Ingrese los numeros de participantes separados por un espacio: ').split()
for i in range(len(a)):
a[i] = int(a[i])
for i in range(0, len(a)-1):
for j in range(0, len(a)-1):
if a[j] > a[j+1]:
a[j], a[j+1] = a[j+1], a[j]
print(a)
def nombres_ordenados(lista):
for a in range(1, len(lista)):
temp = lista[a]
b = a - 1
while b >= 0 and temp < lista[b]:
lista[b + 1] = lista[b]
b = b - 1
lista[b + 1] = temp
print(lista)
def decode(sms):
decoded = ""
# escribe el código aquí
for letter in sms:
if letter != "@":
decoded += letter
return decoded[::-1]
sms = "!@rodamargORP@oredadrev@nu@sere@is¡"
print(decode(sms))
def get_bad_changes(changes):
bad_changes = []
for i in range(len(changes) - 1):
if changes[i + 1] > changes[i]:
bad_changes.append(changes[i + 1])
return bad_changes
changes = [1, 2, 5, 4, 5, 8, 7, 6, 9, 10]
print(get_bad_changes(changes))
lista = [34, 34, 34, 34, 34, 34, 34, 34, 51, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 51, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 51, 34, 34, 34, 34, 51, 51, 34, 51, 51, 34, 34, 51, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 51, 51, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 51, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34
def ordenamientoPorInsercion(unaLista):
for indice in range(1,len(unaLista)):
valorActual = unaLista[indice]
posicion = indice
while posicion>0 and unaLista[posicion-1]>valorActual:
unaLista[posicion]=unaLista[posicion-1]
posicion = posicion-1
unaLista[posicion]=valorActual
return unaLista
sms = "!@rodamargORP@oredadrev@nu@sere@is¡"
def decode(sms):
# replace the @ by nothing
# reverse the string
return sms.replace('@', '')[::-1]
decode(sms)
# Mejora la velocidad de tu programa
import time
print("Bienvenido al programa de mejora de velocidad de tu programa")
print ("Ingresa los tiempos en milisegundos de las etapas de tu programa")
times = []
# Función para agregar los tiempos a nuestra lista
def add_time():
print("\nAgregue un tiempo de la etapa de su programa")
time = float(input())
times.append(time)
print("¿Desea agregar otro tiempo?\n1. Si\n2. No")
response = int(input())
if response == 1:
add_time()
else:
print("Lista de tiempos: ", times)
# Función para identificar los cambios que afectaron negativamente la velocidad
def analyze_times():
print("\nLos cambios que afectaron neg
def insertion_sort(nums):
for i in range(len(nums)):
item_to_insert = nums[i]
j = i - 1
while j >= 0 and nums[j] > item_to_insert:
nums[j + 1] = nums[j]
j -= 1
nums[j + 1] = item_to_insert
return nums
insertion_sort(nums)
def CalcularSalario (horas,tarifa):
salario = horas*tarifa
return salario
horas = int(input("Ingrese el numero de horas trabajadas: "))
tarifa = int(input("Ingrese el valor de la tarifa por hora: "))
print (CalcularSalario(horas,tarifa))
lista = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
for x in range(0 , len(lista)):
if lista[x] > 9:
print(lista[x])
names = ["Jonathan", "Juan", "Maria", "Ana"]
def lista(lista):
max=0
for i in lista:
if i>max:
print(i)
max=i
lista([1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,0])
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def add(a, b):
return a + b
def sub(a, b):
return a - b
def mult(a, b):
return a * b
def div(a, b):
try:
return a / b
except ZeroDivisionError:
return "Division by zero!"
# Importamos la funcion de menu
from menu import menu
# Definimos el menu principal
main_menu = {
"1": add,
"2": sub,
"3": mult,
"4": div
}
# Ejecutamos la funcion de menu
menu(main_menu, 'Choose an operation')
def ordenamiento(lista):
for i in range(1, len(lista)):
val = lista[i]
j = i - 1
while j >= 0:
if lista[j] > val:
lista[j + 1] = lista[j]
else:
break
j = j - 1
lista[j + 1] = val
return lista
lista = [2, 1, 4, 3, 5]
print(ordenamiento(lista))
def func_1(lista):
"""
func_1: Funcion que recibe como parametro una lista y devuelve una nueva lista con los elementos
que cumplen con la condicion de ser mayores al anterior.
"""
lista_2 = []
for i in range(1, len(lista)):
if lista[i] > lista[i-1]:
lista_2.append(lista[i])
return lista_2
func_1([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 5, 10, 15, 20, 25, 20, 25])