SlideShare une entreprise Scribd logo
1  sur  3
SOLVE ONLY USING PYTHON PLEASE
You create a program that will ask the user for a Boolean value for each of five variables - A, B,
C, D; and E. Your program will also ask the user to choose an boolean expression and then your
program will solve that expression with the values provided (stating the final output in the
command prompt as either true or false). Use the following symbols as input for the boolean
expression for AND, "|" for OR. So the input for the Boolean expression would look like A &
B | C | D & E. It is important to note that you must also be able to group the expressions together
as such (A & B) | (C & D) & E. And then there is the most infamous one you must consider: ((A
& B) | C) & (D & E). You must consider as many possible expression as possible and error
check for correct input. Your program must ask the user for the a, b, c,D and E variables
(Boolean values) your program must ask the user which expression to calculate 5 Marks your
program must have a two functions that returns a boolean value one for evaluating an AND
expression one for evaluating an OR expression. the program must decompile the expression and
use the appropriate functions developed the program must print out the decomposed statements
as they are being evaluated The program must return the proper evaluation at the end For
example user input
Solution
def AND(A,B):
return A and B;
def OR(A,B):
return A or B;
def NOT(A):
return not A ;
def getValue(operand,A,B,C,D,E):
if(operand=='A'):
return A;
elif(operand=='B'):
return B;
elif(operand=='C'):
return C;
elif(operand=='D'):
return D;
elif(operand=='E'):
return E;
print('Enter 5 boolean values:');
A=input('A:');
B=input('B:');
C=input('C:');
D=input('D:');
E=input('E:');
L1=[];
L2=[];
exp=input('Enter an boolean expression:');
print('Output');
L1=exp.split('|');
size=len(L1);
for i in range(1,size):
if(len(L1[i])>0):
s=L1[i];
val1=getValue(s[1],A,B,C,D,E);
val2=getValue(s[3],A,B,C,D,E);
L1[i]=AND(val1,val2);
print(L1[i]);
print(' ');
size=len(L1);
i=1;
while(size>1):
while(i<=len(L1)):
if(i+1<=len(L1)):
val1=getValue(L1[i],A,B,C,D,E);
val2=getValue(L1[i+1],A,B,C,D,E);
print(OR(val1,val2));
L2.append(OR(val1,val2));
print(' ');
else:
L2.append(L1[i]);
print(L1[i]);
print(' ');
L1=L2;
L2=[];
size=len(L1);
print(L1[i]);
SOLVE ONLY USING PYTHON PLEASE You create a program that will ask the.docx

Contenu connexe

Similaire à SOLVE ONLY USING PYTHON PLEASE You create a program that will ask the.docx

2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
Raghu nath
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
Dushmanta Nath
 
A Programmable Calculator Design and implement a programmable calc.pdf
A Programmable Calculator Design and implement a programmable calc.pdfA Programmable Calculator Design and implement a programmable calc.pdf
A Programmable Calculator Design and implement a programmable calc.pdf
Alexelectronic1
 

Similaire à SOLVE ONLY USING PYTHON PLEASE You create a program that will ask the.docx (20)

Basics of c++
Basics of c++Basics of c++
Basics of c++
 
2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
 
C++
C++ C++
C++
 
Hw5
Hw5Hw5
Hw5
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
Programming Fundamentals lecture 4
Programming Fundamentals lecture 4Programming Fundamentals lecture 4
Programming Fundamentals lecture 4
 
C Programming
C ProgrammingC Programming
C Programming
 
C# Dot net unit-2.pdf
C# Dot net unit-2.pdfC# Dot net unit-2.pdf
C# Dot net unit-2.pdf
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Basics of C porgramming
Basics of C porgrammingBasics of C porgramming
Basics of C porgramming
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
A Programmable Calculator Design and implement a programmable calc.pdf
A Programmable Calculator Design and implement a programmable calc.pdfA Programmable Calculator Design and implement a programmable calc.pdf
A Programmable Calculator Design and implement a programmable calc.pdf
 
1. overview of c
1. overview of c1. overview of c
1. overview of c
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C programming
C programmingC programming
C programming
 

Plus de rennaknapp

Json File - { -student_id-- 101- -first_name-- -James--.docx
Json File -   {     -student_id-- 101-     -first_name-- -James--.docxJson File -   {     -student_id-- 101-     -first_name-- -James--.docx
Json File - { -student_id-- 101- -first_name-- -James--.docx
rennaknapp
 
John plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docxJohn plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docx
rennaknapp
 

Plus de rennaknapp (20)

Language is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docxLanguage is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docx
 
Land use changes and changing climatic conditions caused by human acti.docx
Land use changes and changing climatic conditions caused by human acti.docxLand use changes and changing climatic conditions caused by human acti.docx
Land use changes and changing climatic conditions caused by human acti.docx
 
Kimberly had to come up With a whictue data collection and analysis pr.docx
Kimberly had to come up With a whictue data collection and analysis pr.docxKimberly had to come up With a whictue data collection and analysis pr.docx
Kimberly had to come up With a whictue data collection and analysis pr.docx
 
Korb et al- (2000) obtained blood samples extracted fom patients infec.docx
Korb et al- (2000) obtained blood samples extracted fom patients infec.docxKorb et al- (2000) obtained blood samples extracted fom patients infec.docx
Korb et al- (2000) obtained blood samples extracted fom patients infec.docx
 
keep it simple pls Create a project named labExamCCCS221 containing fo.docx
keep it simple pls Create a project named labExamCCCS221 containing fo.docxkeep it simple pls Create a project named labExamCCCS221 containing fo.docx
keep it simple pls Create a project named labExamCCCS221 containing fo.docx
 
l Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docx
l   Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docxl   Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docx
l Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docx
 
L0-4 During 2022- Jenny- age 14- lives in a household with her father-.docx
L0-4 During 2022- Jenny- age 14- lives in a household with her father-.docxL0-4 During 2022- Jenny- age 14- lives in a household with her father-.docx
L0-4 During 2022- Jenny- age 14- lives in a household with her father-.docx
 
L0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docx
L0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docxL0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docx
L0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docx
 
Kyle is a student with an emotional behavioral disorder- He has also b.docx
Kyle is a student with an emotional behavioral disorder- He has also b.docxKyle is a student with an emotional behavioral disorder- He has also b.docx
Kyle is a student with an emotional behavioral disorder- He has also b.docx
 
Json File - { -student_id-- 101- -first_name-- -James--.docx
Json File -   {     -student_id-- 101-     -first_name-- -James--.docxJson File -   {     -student_id-- 101-     -first_name-- -James--.docx
Json File - { -student_id-- 101- -first_name-- -James--.docx
 
Make a concept map that shows the hierarchical relationship between th.docx
Make a concept map that shows the hierarchical relationship between th.docxMake a concept map that shows the hierarchical relationship between th.docx
Make a concept map that shows the hierarchical relationship between th.docx
 
Jordan and Alyssa are saving for their daughter Taylor's college educa.docx
Jordan and Alyssa are saving for their daughter Taylor's college educa.docxJordan and Alyssa are saving for their daughter Taylor's college educa.docx
Jordan and Alyssa are saving for their daughter Taylor's college educa.docx
 
John receives $3-400 from an investment at the beginning of every half.docx
John receives $3-400 from an investment at the beginning of every half.docxJohn receives $3-400 from an investment at the beginning of every half.docx
John receives $3-400 from an investment at the beginning of every half.docx
 
Many documents use a specific format for a person's name- Write a prog.docx
Many documents use a specific format for a person's name- Write a prog.docxMany documents use a specific format for a person's name- Write a prog.docx
Many documents use a specific format for a person's name- Write a prog.docx
 
Many crimes- like embezzlement- have definite trends- The demographic.docx
Many crimes- like embezzlement- have definite trends- The demographic.docxMany crimes- like embezzlement- have definite trends- The demographic.docx
Many crimes- like embezzlement- have definite trends- The demographic.docx
 
Management The consequences of unresolved conflict often have devastat.docx
Management The consequences of unresolved conflict often have devastat.docxManagement The consequences of unresolved conflict often have devastat.docx
Management The consequences of unresolved conflict often have devastat.docx
 
Make a star field as in Star Trek (the original series)- like MS's.docx
Make a star field as in Star Trek (the original series)- like  MS's.docxMake a star field as in Star Trek (the original series)- like  MS's.docx
Make a star field as in Star Trek (the original series)- like MS's.docx
 
MAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docx
MAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docxMAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docx
MAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docx
 
John plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docxJohn plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docx
 
John is a part of a team that has been gathered temporarily to develop.docx
John is a part of a team that has been gathered temporarily to develop.docxJohn is a part of a team that has been gathered temporarily to develop.docx
John is a part of a team that has been gathered temporarily to develop.docx
 

Dernier

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Dernier (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

SOLVE ONLY USING PYTHON PLEASE You create a program that will ask the.docx

  • 1. SOLVE ONLY USING PYTHON PLEASE You create a program that will ask the user for a Boolean value for each of five variables - A, B, C, D; and E. Your program will also ask the user to choose an boolean expression and then your program will solve that expression with the values provided (stating the final output in the command prompt as either true or false). Use the following symbols as input for the boolean expression for AND, "|" for OR. So the input for the Boolean expression would look like A & B | C | D & E. It is important to note that you must also be able to group the expressions together as such (A & B) | (C & D) & E. And then there is the most infamous one you must consider: ((A & B) | C) & (D & E). You must consider as many possible expression as possible and error check for correct input. Your program must ask the user for the a, b, c,D and E variables (Boolean values) your program must ask the user which expression to calculate 5 Marks your program must have a two functions that returns a boolean value one for evaluating an AND expression one for evaluating an OR expression. the program must decompile the expression and use the appropriate functions developed the program must print out the decomposed statements as they are being evaluated The program must return the proper evaluation at the end For example user input Solution def AND(A,B): return A and B; def OR(A,B): return A or B; def NOT(A): return not A ; def getValue(operand,A,B,C,D,E): if(operand=='A'): return A; elif(operand=='B'): return B; elif(operand=='C'): return C; elif(operand=='D'): return D; elif(operand=='E'):
  • 2. return E; print('Enter 5 boolean values:'); A=input('A:'); B=input('B:'); C=input('C:'); D=input('D:'); E=input('E:'); L1=[]; L2=[]; exp=input('Enter an boolean expression:'); print('Output'); L1=exp.split('|'); size=len(L1); for i in range(1,size): if(len(L1[i])>0): s=L1[i]; val1=getValue(s[1],A,B,C,D,E); val2=getValue(s[3],A,B,C,D,E); L1[i]=AND(val1,val2); print(L1[i]); print(' '); size=len(L1); i=1; while(size>1): while(i<=len(L1)): if(i+1<=len(L1)): val1=getValue(L1[i],A,B,C,D,E); val2=getValue(L1[i+1],A,B,C,D,E); print(OR(val1,val2)); L2.append(OR(val1,val2)); print(' '); else: L2.append(L1[i]); print(L1[i]); print(' '); L1=L2; L2=[]; size=len(L1); print(L1[i]);