Did I do this right??

A forum for general discussion of the Python programming language.

Did I do this right??

Postby doctterdre » Thu Sep 22, 2016 9:46 pm

Here is the question:
Create a script which yields the propositional logic for BITWISE AND (Conjunction), BITWISE OR (Disjunction), BITWISE XOR (EXCLUSIVE OR), Logical AND, Logical OR, Addition, Multiplication, and Bitwise NOT Inversion. THE OUTPUT SHOULD BE FORMATTED IN SIMILAR FORM AS THE RESULT ON PRIOR PAGE. (the format I know is right)

Here is my code:
Code: Select all
print("BITWISE")

print("x y AND")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x&y)

print("x y OR")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x|y)
       
print("x y XOR")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x^y)
       
print("LOGICAL")

print("x y AND")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x and y)
print("x y OR")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x or y)
       
print("x y Addition")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x + y)
print("x y Multiplication")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x * y)
print("x y NOT")
for x in [0,1]:
    for y in [0,1]:
        print(x,y,x != y)

Thanks
Last edited by ichabod801 on Thu Sep 22, 2016 9:50 pm, edited 1 time in total.
Reason: code tags, first post lock
doctterdre
 
Posts: 8
Joined: Thu Sep 22, 2016 9:44 pm

Re: Did I do this right??

Postby ichabod801 » Thu Sep 22, 2016 9:51 pm

Um, if you know the format is right all you need to check is the mathematical operators. Are you asking us to check if your program's math is right?
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
ichabod801
 
Posts: 688
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Re: Did I do this right??

Postby doctterdre » Thu Sep 22, 2016 10:12 pm

Im asking if I used the right operators
doctterdre
 
Posts: 8
Joined: Thu Sep 22, 2016 9:44 pm

Re: Did I do this right??

Postby micseydel » Thu Sep 22, 2016 10:26 pm

How do you think you can determine the correctness yourself?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Did I do this right??

Postby doctterdre » Thu Sep 22, 2016 10:45 pm

I think they are all right except maybe the last one, bitwise not. is bitwise not != or ~? thanks
doctterdre
 
Posts: 8
Joined: Thu Sep 22, 2016 9:44 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 6 guests