![]() |
Ejercicios resueltos (parte 4) |
Dejo mis soluciones a los problemas planteados en la entrada pasada: ejercicios en python parte 4.
Como siempre digo: esta fue mi manera de resolver los ejercicios, ustedes pueden tener una manera diferente de resolverlos.
También comentarles que los espacios marcados con ---- son sangrías que necesitan las funciones para que todo corra bien (como el editor de blogger no me deja usar sangrías uso esa nomenclatura). Saludos
Ejercicios 1
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import random
def promocion(): #Información del descuento
----print ""
----print "SU GASTO IGUALA O SUPERA LOS $100.00 Y POR TANTO PARTICIPA EN LA PROMOCION."
----print ""
----print " COLOR DESCUENTO"
----print ""
----print " BOLA BLANCA NO TIENE"
----print " BOLA ROJA 10 POR CIENTO"
----print " BOLA AZUL 20 POR CIENTO"
----print " BOLA VERDE 25 POR CIENTO"
----print " BOLA AMARILLA 50 POR CIENTO"
----print ""
def calculo(valor): #Calculo de la función
----descuento = 0
----x = random.choice([0, 10, 20, 25, 50])
----bolas = {0:"BOLA BLANCA", 10:"BOLA ROJA", 20:"BOLA AZUL", 25:"BOLA VERDE", 50:"BOLA AMARILLA"}
----if x == 0:
--------print "ALEATORIAMENTE USTED OBTUVO UNA BOLA BLANCA"
--------print ""
--------print "LAMENTABLEMENTE EN ESTA OPORTUNIDAD NO HAY DESCUENTO"
----else:
--------print "ALEATORIAMENTE USTED OVTUVO UNA", bolas[x]
--------print ""
--------print "FELICIDADES, HA GANADO UN", x, "POR CIENTO DE DESCUENTO"
--------print ""
--------print "SU NUEVO TOTAL A PAGAR ES: $", float (valor -(float(valor * x)/100))
--------print ""
def compras(): #Funcion principal
----valor_compra = raw_input("INTRODUZCA LA CANTIDAD TOTAL DE LA COMPRA: ")
----valor_compra = int(valor_compra)
----if valor_compra < 100:
--------print ""
--------print "El cliente no aplica la promocion!!!"
----else:
--------promocion()
--------calculo(valor_compra)
compras()
Ejercicio 2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
----print "ELIJA EL PRODUCTO DESEADO"
----print ""
----print "PRODUCTO CODIGO"
----print ""
----print "CAMISA........................... 1"
----print "CINTURON......................... 2"
----print "ZAPATOS.......................... 3"
----print "PANTALON......................... 4"
----print "CALCETINES....................... 5"
----print "FALDAS........................... 6"
----print "GORRAS........................... 7"
----print "SUETER........................... 8"
----print "CORBATA.......................... 9"
----print "CHAQUETA......................... 10"
----print ""
----relacion = {1:35, 2:10, 3:50, 4:40, 5:5, 6:20, 7:7, 8:15, 9:10, 10:35}
----codigo = input("INTRODUZCA EL CODIGO: ")
----print ""
----print "EL PRECIO ES: $", relacion[codigo]
----cantidad = input("INTRODUZCA EL NUMERO DE UNIDADES: ")
----print ""
----precio_t = float(relacion[codigo] * cantidad)
----print "EL TOTAL A PAGAR ES: $", precio_t
main()
Ejercicio 3
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import time
def main():
----print "CATEGORIA PRECIO CODIGO RECARGO/DIA DE ATRASO"
----print ""
----print "FAVORITOS $2.50 1 $0.50"
----print "NUEVOS $3.00 2 $0.75"
----print "ESTRENOS $3.50 3 $1.00"
----print "SUPER ESTRENOS $4.00 4 $1.50"
----print ""
----codigo = raw_input("INTRODUZCA EL CODIGO DE LA CATEGORIA DE LA PELICULA: ")
----n_dias = raw_input("INTRODUZCA EL NUMERO DE DIAS DE ATRASO EN LA DEVOLUCION: ")
----print ""
----n_dias = int(n_dias)
----total = 0
----if codigo == "1":
--------total = float(2.50 + (0.50 * n_dias))
--------print "EL TOTAL A PAGAR ES: $",total, "dolares"
----elif codigo == "2":
--------total = float(3.00 + (0.75 * n_dias))
--------print "EL TOTAL A PAGAR ES: $", total, "dolares"
----elif codigo == "3":
--------total = float(3.50 + (1.00 * n_dias))
--------print "EL TOTAL A PAGAR ES: $", total, "dolares"
----elif codigo == "4":
--------total = float(4.00 + (1.50 * n_dias))
--------print "EL TOTAL A PAGAR ES: $", total, "dolares"
----else:
--------print "OPCION INCORRECTA, VUELVA A INTENTARLO..."
--------time.sleep(2)
--------os.system("cls")
--------main()
main()
Cualquier duda o sugerencia dejar comentarios debajo de la entrada, saludos: Diego.