Inclusão Comparador de Magnitude
This commit is contained in:
parent
b607a62adc
commit
1da5ec1355
|
@ -2,7 +2,6 @@
|
||||||
/2SNA_Somativa.py
|
/2SNA_Somativa.py
|
||||||
/AdivinharNumero.py
|
/AdivinharNumero.py
|
||||||
/Aula semana 01_06 à 05_06-1.pdf
|
/Aula semana 01_06 à 05_06-1.pdf
|
||||||
/ComparadorDeMagnitude.py
|
|
||||||
/__pycache__
|
/__pycache__
|
||||||
/nivel_dificil.py
|
/nivel_dificil.py
|
||||||
/nivel_facil.py
|
/nivel_facil.py
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
import portas, trataDados
|
||||||
|
|
||||||
|
# Dados de entrada
|
||||||
|
a = []
|
||||||
|
b = []
|
||||||
|
|
||||||
|
#Entrada A
|
||||||
|
for i in range(0, 4):
|
||||||
|
a.append(trataDados.entradaBinaria("Entre com o valor de A["+str(i)+"]:","Valor inválido!"))
|
||||||
|
|
||||||
|
#Entrada B
|
||||||
|
for i in range(0, 4):
|
||||||
|
b.append(trataDados.entradaBinaria("Entre com o valor de B[" + str(i) + "]:", "Valor inválido!"))
|
||||||
|
|
||||||
|
# Exibir Entradas
|
||||||
|
#for i in range(0, 4):
|
||||||
|
# print("A[",i,"] = ", a[i], " => B[",i,"] = ", b[i])
|
||||||
|
|
||||||
|
print("a = ",a[3],a[2],a[1],a[0])
|
||||||
|
print("b = ",b[3],b[2],b[1],b[0])
|
||||||
|
|
||||||
|
# Fase 1 - GT e EQ
|
||||||
|
#print("Fase 1 => GT e EQ")
|
||||||
|
gt = []
|
||||||
|
eq = []
|
||||||
|
for i in range(0, 4):
|
||||||
|
gt.append(portas.portaAnd(a[i], portas.portaNot(b[i])))
|
||||||
|
eq.append(portas.portaXnor(a[i], b[i]))
|
||||||
|
|
||||||
|
print("")
|
||||||
|
|
||||||
|
# Fase 2 - A > B
|
||||||
|
# U10
|
||||||
|
u10 = portas.portaAnd(gt[0], eq[1])
|
||||||
|
|
||||||
|
# U11
|
||||||
|
u11 = portas.portaOr(u10, gt[1])
|
||||||
|
|
||||||
|
# U12
|
||||||
|
u12 = portas.portaAnd(u11, eq[2])
|
||||||
|
|
||||||
|
# U13
|
||||||
|
u13 = portas.portaOr(u12, gt[2])
|
||||||
|
|
||||||
|
# U14
|
||||||
|
u14 = portas.portaAnd(u13, eq[3])
|
||||||
|
|
||||||
|
# U15
|
||||||
|
u15 = portas.portaOr(u14, gt[3])
|
||||||
|
|
||||||
|
|
||||||
|
# Fase 3 - A = B
|
||||||
|
# U17
|
||||||
|
u17 = portas.portaAnd(eq[0], eq[1])
|
||||||
|
|
||||||
|
# U18
|
||||||
|
u18 = portas.portaAnd(eq[2], eq[3])
|
||||||
|
|
||||||
|
# U19
|
||||||
|
u19 = portas.portaAnd(u17, u18)
|
||||||
|
|
||||||
|
# Fase 4 - A < B
|
||||||
|
# U16
|
||||||
|
u16 = portas.portaNor(u15, u19)
|
||||||
|
|
||||||
|
# Resultados
|
||||||
|
print("A > B => ", u15)
|
||||||
|
print("A = B => ", u19)
|
||||||
|
print("A < B => ", u16)
|
18
portas.py
18
portas.py
|
@ -1,30 +1,30 @@
|
||||||
|
|
||||||
def portaAnd(x,y):
|
def portaAnd(x,y):
|
||||||
return (x*y);
|
return (x*y)
|
||||||
|
|
||||||
def portaOr(x,y):
|
def portaOr(x,y):
|
||||||
if((x+y)>0):
|
if((x+y)>0):
|
||||||
return 1;
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0;
|
return 0
|
||||||
|
|
||||||
def portaNot(x):
|
def portaNot(x):
|
||||||
if(x==0):
|
if(x==0):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0;
|
return 0
|
||||||
|
|
||||||
def portaNand(x,y):
|
def portaNand(x,y):
|
||||||
return portaNot(portaAnd(x,y));
|
return portaNot(portaAnd(x,y))
|
||||||
|
|
||||||
def portaNor(x,y):
|
def portaNor(x,y):
|
||||||
return portaNot(portaOr(x,y));
|
return portaNot(portaOr(x,y))
|
||||||
|
|
||||||
def portaXor(x,y):
|
def portaXor(x,y):
|
||||||
if(portaAnd(x,y) == portaOr(x,y)):
|
if(portaAnd(x,y) == portaOr(x,y)):
|
||||||
return 0;
|
return 0
|
||||||
else:
|
else:
|
||||||
return 1;
|
return 1
|
||||||
|
|
||||||
def portaXnor(x,y):
|
def portaXnor(x,y):
|
||||||
return portaNot(portaXor(x,y));
|
return portaNot(portaXor(x,y))
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
import portas;
|
import portas
|
||||||
|
|
||||||
# Dados de entrada
|
# Dados de entrada
|
||||||
a = [0, 0, 1, 1];
|
a = [0, 0, 1, 1]
|
||||||
b = [0, 1, 0, 1];
|
b = [0, 1, 0, 1]
|
||||||
|
|
||||||
# Porta AND
|
# Porta AND
|
||||||
print("Porta AND");
|
print("Porta AND")
|
||||||
for count in range(0,4):
|
for count in range(0,4):
|
||||||
print("a = ",a[count]," b = ",b[count]," => a AND b =",portas.portaAnd(a[count],b[count]));
|
print("a = ",a[count]," b = ",b[count]," => a AND b =",portas.portaAnd(a[count],b[count]))
|
||||||
print("");
|
print("")
|
||||||
|
|
||||||
# Porta OR
|
# Porta OR
|
||||||
print("Porta OR");
|
print("Porta OR")
|
||||||
for count in range(0,4):
|
for count in range(0,4):
|
||||||
print("a = ",a[count]," b = ",b[count]," => a OR b =",portas.portaOr(a[count],b[count]));
|
print("a = ",a[count]," b = ",b[count]," => a OR b =",portas.portaOr(a[count],b[count]))
|
||||||
print("");
|
print("")
|
||||||
|
|
||||||
# Porta NOT
|
# Porta NOT
|
||||||
print("Porta NOT");
|
print("Porta NOT")
|
||||||
print("a = 0 => a NOT = ",portas.portaNot(0));
|
print("a = 0 => a NOT = ",portas.portaNot(0))
|
||||||
print("a = 1 => a NOT = ",portas.portaNot(1));
|
print("a = 1 => a NOT = ",portas.portaNot(1))
|
||||||
print("");
|
print("")
|
||||||
|
|
||||||
# Porta NAND
|
# Porta NAND
|
||||||
print("Porta NAND");
|
print("Porta NAND")
|
||||||
for count in range(0,4):
|
for count in range(0,4):
|
||||||
print("a = ",a[count]," b = ",b[count]," => a NAND b =",portas.portaNand(a[count],b[count]));
|
print("a = ",a[count]," b = ",b[count]," => a NAND b =",portas.portaNand(a[count],b[count]))
|
||||||
print("");
|
print("")
|
||||||
|
|
||||||
# Porta NOR
|
# Porta NOR
|
||||||
print("Porta NOR");
|
print("Porta NOR")
|
||||||
for count in range(0,4):
|
for count in range(0,4):
|
||||||
print("a = ",a[count]," b = ",b[count]," => a OR b =",portas.portaNor(a[count],b[count]));
|
print("a = ",a[count]," b = ",b[count]," => a OR b =",portas.portaNor(a[count],b[count]))
|
||||||
print("");
|
print("")
|
||||||
|
|
||||||
# Porta XOR
|
# Porta XOR
|
||||||
print("Porta XOR");
|
print("Porta XOR")
|
||||||
for count in range(0,4):
|
for count in range(0,4):
|
||||||
print("a = ",a[count]," b = ",b[count]," => a XOR b =",portas.portaXor(a[count],b[count]));
|
print("a = ",a[count]," b = ",b[count]," => a XOR b =",portas.portaXor(a[count],b[count]))
|
||||||
print("");
|
print("")
|
||||||
|
|
||||||
# Porta XNOR
|
# Porta XNOR
|
||||||
print("Porta XNOR");
|
print("Porta XNOR")
|
||||||
for count in range(0,4):
|
for count in range(0,4):
|
||||||
print("a = ",a[count]," b = ",b[count]," => a XNOR b =",portas.portaXnor(a[count],b[count]));
|
print("a = ",a[count]," b = ",b[count]," => a XNOR b =",portas.portaXnor(a[count],b[count]))
|
||||||
print("");
|
print("")
|
|
@ -4,45 +4,41 @@ def entradaBinaria(txt, txtInvalido):
|
||||||
entrada = int(input(txt))
|
entrada = int(input(txt))
|
||||||
if not 0 <= entrada <= 1:
|
if not 0 <= entrada <= 1:
|
||||||
raise ValueError(txtInvalido)
|
raise ValueError(txtInvalido)
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
print(txtInvalido)
|
print(txtInvalido)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
return entrada;
|
return entrada
|
||||||
|
|
||||||
|
|
||||||
def entradaInt0a100(txt, txtInvalido):
|
def entradaInt0a100(txt, txtInvalido):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
entrada = int(input(txt))
|
entrada = int(input(txt))
|
||||||
if not 0 <= entrada <= 100:
|
if not 0 <= entrada <= 100:
|
||||||
raise ValueError(txtInvalido);
|
raise ValueError(txtInvalido)
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
print(txtInvalido);
|
print(txtInvalido)
|
||||||
else:
|
else:
|
||||||
break;
|
break
|
||||||
|
return entrada
|
||||||
return entrada;
|
|
||||||
|
|
||||||
|
|
||||||
def entradaInt1a3(txt, txtInvalido):
|
def entradaInt1a3(txt, txtInvalido):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
entrada = int(input(txt))
|
entrada = int(input(txt))
|
||||||
if not 1 <= entrada <= 3:
|
if not 1 <= entrada <= 3:
|
||||||
raise ValueError(txtInvalido);
|
raise ValueError(txtInvalido)
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
print(txtInvalido);
|
print(txtInvalido)
|
||||||
else:
|
else:
|
||||||
break;
|
break
|
||||||
|
return entrada
|
||||||
return entrada;
|
|
||||||
|
|
||||||
def comparaInt(a, b):
|
def comparaInt(a, b):
|
||||||
if (a>b):
|
if (a>b):
|
||||||
retorno = ">";
|
retorno = ">"
|
||||||
elif(a<b):
|
elif(a<b):
|
||||||
retorno = "<";
|
retorno = "<"
|
||||||
else:
|
else:
|
||||||
retorno = "=";
|
retorno = "="
|
||||||
return retorno;
|
return retorno
|
Loading…
Reference in New Issue