0% encontró este documento útil (0 votos)
91 vistas11 páginas

Ejercicios de Programacion

Este documento contiene 13 ejercicios de programación en Python. Los ejercicios resuelven problemas matemáticos utilizando funciones, condicionales e iteraciones. Calculan raíces, factoriales, conversiones entre sistemas numéricos y crean matrices.

Cargado por

Adree Lublin
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
91 vistas11 páginas

Ejercicios de Programacion

Este documento contiene 13 ejercicios de programación en Python. Los ejercicios resuelven problemas matemáticos utilizando funciones, condicionales e iteraciones. Calculan raíces, factoriales, conversiones entre sistemas numéricos y crean matrices.

Cargado por

Adree Lublin
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 11

Parte 1.

Ejercicio 6.

import cmath

a = int (input("Escriba un número:"))

b = int (input("Escriba un segundo número:"))

c = int (input("Escriba un tercer número:"))

# calculate the discriminant

d = (b**2) - (4*a*c)

# find two solutions

sol1 = (-b-cmath.sqrt(d))/(2*a)

sol2 = (-b+cmath.sqrt(d))/(2*a)

print('The solution are {0} and {1}'.format(sol1,sol2))


Ejercicio 8.

usuario = int (input("por favor, escriba un número de las siguientes


opciones:\n 1 --> int\n 2 --> float\n 3 --> string\n... y presione Enter "))

if usuario == 1:

primera = int (input("Por favor ingrese un número entero:"))

print (f"Usted escribio: {primera}\n El resultado es: {(primera+1)} ")

if usuario == 2:

segunda = float (input("Por favor ingrese un número decimal:"))

print (f"Usted escribio: {segunda}\n El resultado es: {(segunda+1)} ")

elif usuario == 3:

tercer = input ("Por favor ingrese un texto:")

c= "*"

print (f"Usted escribio: {tercer}\n El resultado es: {(tercer + c)} ")


Ejercicio 10.

usuario = int (input("Escribe una puntuación del (1 al 9):"))

if usuario == 0:

print ("Lo sentimos, pero la puntaciones empiezan en el 1 y finalizan en 9.")

elif usuario >= 1 and usuario <= 3:

print (f"Escribistes {usuario}\nTu puntaje final es: {usuario * 10}")

elif usuario >= 4 and usuario <= 6 :

print (f"Escribistes: {usuario}\n Tu puntaje final es: {usuario * 100}")

elif usuario >= 7 and usuario <= 9 :

print (f"Escribistes: {usuario}\n Tu puntaje final es: {usuario * 1000}")

else:

print ("Lo sentimos, no existe dicha puntuación en este programa.")


Ejercicio 11.

y=int(input("Number To Words Converter:-\n\nEnter Number: "))

x,tyu=str(y),print("\n")

import sys

if int(x)>10**100 or int(x)<0:sys.exit("Range Is From Zero To One Googol!")

def
num1wrd(x,w={0:"",1:"One",2:"Two",3:"Three",4:"Four",5:"Five",6:"Six",7:"Seven",8:"Ei
ght",9:"Nine"},f={2:"Twen",3:"Thir",4:"For",5:"Fif",6:"Six",7:"Seven",8:"Eigh",9:"Nin
e"},t={11:"Eleven",12:"Twelve",13:"Thirteen",14:"Fourteen",15:"Fifteen",16:"Sixteen",
17:"Seventeen",18:"Eighteen",19:"Nineteen"}):

if len(x)==1:return(w[int(x)])

elif len(x)==2 and x[0]=="0" and x[1]=="0":return("")

elif len(x)==2 and x[0]=="0":return (w[int(x[1])])

elif len(x)==2:

if int(x) in range(11,20):return(t[int(x)])

elif int(x[1])==0:

if int(x)==10:return("Ten")

else:return(f[int(x[0])]+"ty")

else:return(f[int(x[0])]+"ty"+"-"+w[int(x[1])])

def
hun_num(x,w1={0:"",1:"One",2:"Two",3:"Three",4:"Four",5:"Five",6:"Six",7:"Seven",8:"E
ight",9:"Nine"}):

if len(x)==3 and x[0]!="0" and x[1]=="0" and x[2]=="0": return(w1[int(x[0])]+"


"+"Hundred")

elif len(x)==3 and x[0]!="0":

a1=(x[1]+x[2])

return(w1[int(x[0])]+" "+"Hundred "+"and "+num1wrd(a1))

elif len(x)==3 and x[0]=="0": return(num1wrd(x[1]+x[2])+" ")

else: return(num1wrd(x))

def seg3(s,out = []):


while len(s):

out.insert(0, s[-3:])

s = s[:-3]

return out

def q(x):

if x=="000":return(0)

elif x=="00":return(0)

elif x=="0":return(0)

else:return(1)

aa,v={0:"",1:"Thousand",2:"Million",3:"Billion",4:"Trillion",5:"Quadrillion",6:"Quint
illion",7:"Hextillion",8:"Septillion",9:"Octillion",10:"Nonillion",11:"Decillion",12:
"Undecillion",13:"Duodecillion",15:"Quattuordecillion",16:"Quindecillion",17:"Hexdeci
llion",18:"Septdecillion",19:"Octodecillion",20:"Novemdecillion",21:"Vigintillion",14
:"Tredecillion",22:"Unvigintillion",23:"Duovigintillion",24:"Trevigintillion",25:"Qua
ttuorvigintillion",26:"Quinvigintillion",27:"Hexvigintillion",28:"Septvigintillion",2
9:"Octovigintillion",30:"Novemvigintillion",31:"Trigintillion",32:"Untrigintillion",3
3:"Duotrigintillion"},seg3(x)

if int(x)==10**100: s="One Googol"

elif int(x)==0: s="Zero"

else:

s1=""

for i in range(len(v)):s1=s1+(hun_num(v[i]))+(" "+aa[len(v)-1-i]+", ")*q(v[i])

s=s1[:len(s1)-3]

print("》 "+s+".")
Ejercicio 7.

usuario = int(input("(a) Escriba un numero: "))

usuario_2 = int(input("(b) Escriba un numero: "))

usuario_3 = int(input("(c) Escriba un numero: "))

usuario_4 = int(input("(d) Escriba un numero: "))

usuario_5 = int(input("(e) Escriba un numero: "))

if usuario > usuario_2 and usuario > usuario_3 and usuario > usuario_4 and
usuario > usuario_5:

print (f"\n El número mayor es la opción (a): {usuario}")

elif usuario_2 > usuario and usuario_2 > usuario_3 and usuario_2 > usuario_4 and
usuario_2 > usuario_5:

print (f"\n El número mayor es la opción (b): {usuario_2}")

elif usuario_3 > usuario and usuario_3 > usuario_2 and usuario_3 > usuario_4 and
usuario_3 > usuario_5:

print (f"\n El número mayor es la opción (c): {usuario_3}")

elif usuario_4 > usuario and usuario_4 > usuario_2 and usuario_4 > usuario_3 and
usuario_2 > usuario_5:

print (f"\n El número mayor es la opción (d): {usuario_4}")

elif usuario_5 > usuario and usuario_5 > usuario_2 and usuario_5 > usuario_3 and
usuario_5 > usuario_4:

print (f"\n El número mayor es la opción (e): {usuario_5}")


Parte 2.

Ejercicio 6.

numero1 = int(input("Ingrese un valor para N: (1<k<N)"))

numero2 = int(input("Ingrese un valor para K: (1<k<N)"))

if numero1 >= 0:

factorial = 1

if numero1 == 0 or numero1 == 1:

factorial = 1

else:

for i in range (1, numero1 + 1):

factorial *= i

if numero2 >= 0:

factorial2 = 1

if numero2 == 0 or numero1 == 1:

factorial2 = 1

else:

for i in range (1, numero2 + 1):

factorial2 *= i

print ()

calculo = factorial/factorial2

print (calculo)
Ejercicio 7.

#Write a program that calculates N!*K!/(N-K)! for given N and K (1 < K < N)

numero1 = int(input("Ingrese un valor para N: (1 <k <N)"))

numero2 = int(input("Ingrese un valor para K: (1 <k <N)"))

if numero1 > 0:

factorial = 1

if numero1 == 0 or numero1 == 1:

factorial = 1

else:

for i in range (1, numero1 + 1):

factorial*= i

if numero2 >= 0:

factorial2 = 1

if numero2 == 0 or numero1 == 1:

factorial2 = 1

else:

for i in range (1, numero2 + 1):

factorial2*= i

calculo = factorial * factorial2 / (factorial - factorial2)

print (calculo)

Ejercicio 10.

def crear_matriz (m,n):

print ("\n")

for m in range (1,21):


for n in range (1,21):

print (f" ({m*n})", end = " ")

print ("")

filas = int(input("Digite la cantidad de filas:"))

columnas = int(input("Digite la cantidad de columnas"))

matriz = crear_matriz (filas, columnas)

print (matriz)

Ejercicio 12.

numero_decimal = float (input("Digite un numero: "))

contenedor = numero_decimal

numero_binario = 0

multiplicador = 1

while numero_decimal != 0:

numero_binario = numero_binario + numero_decimal % 2 * multiplicador

numero_decimal //= 2

multiplicador *= 10

print(f"El número introducido fue: {contenedor}\n Su conversión a binario es:


{numero_binario}")
Ejercicio 13.

numero_binario = str (input("Ingrese el numero a transformar:"))

numero_decimal = 0 #aquí iremos sumando el resultado de cada multiplicación

for posicion, digito_string in enumerate(numero_binario[::-1]):

numero_decimal += int(digito_string) * 2 ** posicion

print(f'El número decimal que buscamos es {numero_decimal}')

También podría gustarte