İçeriğe geç

Perceptron And, OR, XOR Problem Solving With Python Codes

# -*- coding: utf-8 -*-
"""
Created on Wed Feb 19 17:33:07 2020

@author: recai.cansiz
"""

# %% And Gateway
# First Value (w) is 1 
w = int(input("w : "))

# And Gateway
and_results = [[0,0], [0,1], [1,0], [1,1]]

for i in and_results:

    a = i[0] * w
    b = i[1] * w
    
    r = a + b
    
    if r >= 1.5:
        print("It worked : ", r)
    else: 
        print("It didn't work: ", r)
        
# %% OR Gateway Default Value is 1
w = int(input("w : "))

# OR Gateway
or_results = [[0,0], [0,1], [1,0], [1,1]]

for i in or_results:

    a = i[0] * w
    b = i[1] * w
    
    r = a + b
    
    if r >= 0.5:
        print("It worked : ", r)
    else: 
        print("It didn't work : ", r)        

# %% XOR Gateway Default Value is 1
w = int(input("w : "))
# We set w2 which is -1
w2 = int(input("w2 : "))

# XOR Gateway
xor_results = [[0,0], [0,1], [1,0], [1,1]]

for i in xor_results:
    
    #w
    a = i[0] * w
    b = i[1] * w
    r = a + b
    
    #w2
    a2 = i[0] * w2
    b2 = i[1] * w2
    r2 = a2 + b2
    
    if r >= 0.5 and r2 >= -1.5:
        print("It worked.")
    else:
        print("It didn't work.")
        
Tarih:AI

İlk Yorumu Siz Yapın

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir