Initial commit
This commit is contained in:
commit
9a3ad1ec49
30
portas.py
Normal file
30
portas.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
def portaAnd(x,y):
|
||||
return (x*y);
|
||||
|
||||
def portaOr(x,y):
|
||||
if((x+y)>0):
|
||||
return 1;
|
||||
else:
|
||||
return 0;
|
||||
|
||||
def portaNot(x):
|
||||
if(x==0):
|
||||
return 1
|
||||
else:
|
||||
return 0;
|
||||
|
||||
def portaNand(x,y):
|
||||
return portaNot(portaAnd(x,y));
|
||||
|
||||
def portaNor(x,y):
|
||||
return portaNot(portaOr(x,y));
|
||||
|
||||
def portaXor(x,y):
|
||||
if(portaAnd(x,y) == portaOr(x,y)):
|
||||
return 0;
|
||||
else:
|
||||
return 1;
|
||||
|
||||
def portaXnor(x,y):
|
||||
return portaNot(portaXor(x,y));
|
47
testaPortas.py
Normal file
47
testaPortas.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import portas;
|
||||
|
||||
# Dados de entrada
|
||||
a = [0, 0, 1, 1];
|
||||
b = [0, 1, 0, 1];
|
||||
|
||||
# Porta AND
|
||||
print("Porta AND");
|
||||
for count in range(0,4):
|
||||
print("a = ",a[count]," b = ",b[count]," => a AND b =",portas.portaAnd(a[count],b[count]));
|
||||
print("");
|
||||
|
||||
# Porta OR
|
||||
print("Porta OR");
|
||||
for count in range(0,4):
|
||||
print("a = ",a[count]," b = ",b[count]," => a OR b =",portas.portaOr(a[count],b[count]));
|
||||
print("");
|
||||
|
||||
# Porta NOT
|
||||
print("Porta NOT");
|
||||
print("a = 0 => a NOT = ",portas.portaNot(0));
|
||||
print("a = 1 => a NOT = ",portas.portaNot(1));
|
||||
print("");
|
||||
|
||||
# Porta NAND
|
||||
print("Porta NAND");
|
||||
for count in range(0,4):
|
||||
print("a = ",a[count]," b = ",b[count]," => a NAND b =",portas.portaNand(a[count],b[count]));
|
||||
print("");
|
||||
|
||||
# Porta NOR
|
||||
print("Porta NOR");
|
||||
for count in range(0,4):
|
||||
print("a = ",a[count]," b = ",b[count]," => a OR b =",portas.portaNor(a[count],b[count]));
|
||||
print("");
|
||||
|
||||
# Porta XOR
|
||||
print("Porta XOR");
|
||||
for count in range(0,4):
|
||||
print("a = ",a[count]," b = ",b[count]," => a XOR b =",portas.portaXor(a[count],b[count]));
|
||||
print("");
|
||||
|
||||
# Porta XNOR
|
||||
print("Porta XNOR");
|
||||
for count in range(0,4):
|
||||
print("a = ",a[count]," b = ",b[count]," => a XNOR b =",portas.portaXnor(a[count],b[count]));
|
||||
print("");
|
48
trataDados.py
Normal file
48
trataDados.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
def entradaBinaria(txt, txtInvalido):
|
||||
while True:
|
||||
try:
|
||||
entrada = int(input(txt))
|
||||
if not 0 <= entrada <= 1:
|
||||
raise ValueError(txtInvalido)
|
||||
except ValueError as e:
|
||||
print(txtInvalido)
|
||||
else:
|
||||
break
|
||||
return entrada;
|
||||
|
||||
|
||||
def entradaInt0a100(txt, txtInvalido):
|
||||
while True:
|
||||
try:
|
||||
entrada = int(input(txt))
|
||||
if not 0 <= entrada <= 100:
|
||||
raise ValueError(txtInvalido);
|
||||
except ValueError as e:
|
||||
print(txtInvalido);
|
||||
else:
|
||||
break;
|
||||
|
||||
return entrada;
|
||||
|
||||
|
||||
def entradaInt1a3(txt, txtInvalido):
|
||||
while True:
|
||||
try:
|
||||
entrada = int(input(txt))
|
||||
if not 1 <= entrada <= 3:
|
||||
raise ValueError(txtInvalido);
|
||||
except ValueError as e:
|
||||
print(txtInvalido);
|
||||
else:
|
||||
break;
|
||||
|
||||
return entrada;
|
||||
|
||||
def comparaInt(a, b):
|
||||
if (a>b):
|
||||
retorno = ">";
|
||||
elif(a<b):
|
||||
retorno = "<";
|
||||
else:
|
||||
retorno = "=";
|
||||
return retorno;
|
Loading…
Reference in a new issue