Questions
all python Question One [2 * 2.5] Write a program that prompts the user for two...

all python

Question One [2 * 2.5]

  1. Write a program that prompts the user for two integers and then prints

•The sum

•The difference

•The product

•The average

•The distance (absolute value of the difference)

•The maximum (the larger of the two)

•The minimum (the smaller of the two)

Hint: Python defines max and min functions that accept a sequence of values, each separated with a comma.

  1. Write a program that prompts the user for a measurement in meters and then converts it to miles, feet, and inches.

  1. Write a program that reads three numbers and prints “all the same” if they are all the same, “all different” if they are all different, and “neither” otherwise.

  1. Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or –. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F–. A + increases the numeric value by 0.3, a – decreases it by 0.3. However, an A+ has value 4.0.

Example:

Enter a letter grade: B-

The numeric value is 2.7.

  1. Test and Correct and the following program:                 
Grade = 99
 
if Grade>= 90:

    print("A")

if Grade >=80 :

    print("B")

if Grade >=70 :

    print("C")

if Grade >=60:

    print("D")

else:

    print("Failed")

In: Computer Science

A direct-mapped cache consists of 8 blocks. Byte-addressable main memory contains 4K blocks of 8 bytes...

A direct-mapped cache consists of 8 blocks. Byte-addressable main memory contains 4K blocks of 8 bytes each. Access time for the cache is 22ns, and the time required to fill a cache slot from main memory is 300ns. (This time allows us to determine the block is missing and bring it into cache.) Assume a request is always started in parallel to both cache and to main memory(so if it is not found in cache, we do not have to add this cache search time to the memory access). If a block is missing from cache, the entire block is brought into the cache and the access is restarted. Initially, the cache is empty.
-Compute the hit rate for a program that loops 4 times from locations 0x0 to 0x43 (address 0 hex to address 43 hex).
-Compute the effective access time for this program.

In: Computer Science

Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the...

Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the requirements for trap.cpp:

Write a main program in a file called trap.cpp that solves the following scenario, using your Grid class:

Giant Mole People have risen from their underground lairs and are taking over the world. You have been taken prisoner and placed in an underground jail cell. Since the Mole People are blind and don't know how to build doors, your cell has one open exit (no door). Since you are deep underground, it is completely dark and you cannot see. Your task is to escape your prison to join the human resistance!

Your program should ask the user to input the number of rows, then columns, for the grid. (Note that this is the ONLY keyboard input for this program). Create a grid with the specified number of rows and columns, using the constructor with two parameters -- (this is the one that should automatically create a fenced-in grid containing one exit and a randomly placed mover). Display the initial grid. Since the placement of the exit and the mover is random, execution of this program will look a little different every time. Your task is to escape the trap! You will need to create an algorithm that will instruct the mover to find its way to the exit. (Hint: Think about how to use the Predicate functions before you move). Upon reaching the exit, you should print a message of success, like "We escaped!", and then output the final position of the mover. Keep the path toggled ON. You only need to display the initial setup grid and the final grid for this program.

Here is the header file grid.h:

#include <iostream>
using namespace std;

class Grid
{
public:
static const int NORTH = 0;
static const int WEST = 1;
static const int SOUTH = 2;
static const int EAST = 3;

Grid(); // build 1 x 1 grid with mover in only
// square, facing east

Grid(int r, int c); // build grid with r rows, c cols, blocks around edge with random exit
// and random mover position and direction

Grid(int r, int c, int mr, int mc, int d); // build empty grid with r rows, c cols, and mover at row mr, col mc, and facing direction d

bool Move(int s); // move forward s spaces, if possible

void TogglePath(); // toggle whether or not moved path is shown

void TurnLeft(); // turn the mover to the left

void PutDown(); // put down an item at the mover's position

bool PutDown(int r, int c); // put down an item at (r,c), if possible

bool PickUp(); // pick up item at current position

bool PlaceBlock(int r, int c); // put a block at (r,c), if possible

void Grow(int gr, int gc); // grow the grid by gr rows, gc columns

void Display() const; // display the grid on screen. Accessors

bool FrontIsClear() const; // check to see if space in front of mover is clear

bool RightIsClear() const; // check to see if space to right of mover is clear

int GetRow() const; // return row of the mover

int GetCol() const; // return column of the mover

int GetNumRows() const; // return number of rows in the grid

int GetNumCols() const; // return number of columns in the grid

private:

char** grid;

int mover_r, mover_c, mover_d, maxRow, maxCol;

bool path;
  
};

Task

You will write a class called Grid, and test it with a couple of programs. A Grid object will be made up of a grid of positions, numbered with rows and columns. Row and column numbering start at 0, at the top left corner of the grid. A grid object also has a "mover", which can move around to different locations on the grid. Obstacles (which block the mover) and other objects (that can be placed or picked up) are also available. Here is a sample picture of a Grid object in its display format:

0 . . .    This is a Grid object with 4 rows and 4 columns (numbered 0 - 3). 
. . > .    The mover '>' is at row 1, column 2, facing east. 
. . . .    The obstacle '#' is at row 3, column 1 
. # . .    The other item '0' is at row 0, column 0

The @ character indicates that the mover and an item (0) currently occupy the same position on the grid.

Program Details and Requirements

1) Grid class

Download this starter file: grid_starter.h and rename it as grid.h. Your member function prototypes are already given in this file. You will need to add appropriate member data. You will also need to define each of the member functions in the file grid.cpp. You may add whatever member data you need, but you must store the grid itself as a two-dimensional array. Maximum grid size will be 40 rows and 40 columns. (Note that this means dynamic allocation will NOT be needed for this assignment).

Meaning of Grid symbols

.       empty spot on the grid
0       an item that can be placed, or picked up
#       a block (an obstacle).  Mover cannot move through it
<    mover facing WEST
>    mover facing EAST
^       mover facing NORTH
v       mover facing SOUTH
@       mover occupying same place as item (0)

A printed space ' ' in a grid position represents a spot that the mover has already moved through when the path display is toggled on

public Member function descriptions

  • Grid()
    The default constructor should create a 1 x 1 grid, with the mover in the only position, facing EAST
  • Grid(int r, int c)
    The two-parameter constructor will accept two integers, representing rows and columns. Create a grid with r rows and c columns. If either of these is less than 3, default it to 3. If either is greater than the max number of rows or columns, default it to the max number. This grid should be built such that blocks are placed all around the edge, with one random exit (i.e. with no block). The mover should be in a random position and facing a random direction within the grid. When setting up the randomness, make sure each possibility has an equal chance of happening. For example, the random direction has 4 possibilities, so each one should happen about 25% of the time. For the random exit, it will be sufficient to pick a random wall first, then pick a random location on that wall (note that the exit cannot be in a corner spot).

    You'll need the library cstdlib for the srand and rand functions. While it's not normally the best place to do it, you can go ahead and seed the random number generator here in the constructor in some appropriate way so that it's different for seperate program runs.

    If you need a refresher on pseudo-random number generation, see this notes set from COP 3014: http://www.cs.fsu.edu/~myers/c++/notes/rand.html

  • Grid(int r, int c, int mr, int mc, int d)
    This constructor (5 parameters) takes in the following information, in this order:
    • number of starting rows for the grid (if out of range, adjust like in the 2-parameter constructor, although minimum in this case is 1)
    • number of starting columns for the grid (if out of range, adjust like in the 2-parameter constructor, although minimum in this case is 1)
    • The starting row position of the mover (if out of range, adjust to the first or last row, whichever is closer)
    • The starting column position of the mover (if out of range, adjust to the first or last column, whichever is closer)
    • The starting direction of the mover
    Build the starting grid based on the incoming parameters and their descriptions above. Other than the mover, this grid starts out empty.
  • Display()
    This function should print out "The Grid:" on one line, then output the full grid below it -- place spaces between columns so that outputs line up more evenly. End with a newline (so that any next output will be on a separate line). If the path setting is toggled to ON, then any position the mover has already moved through should show up blank. If the path setting is toggled to OFF, then all empty grid spaces show up as dots '.'
    Examples of the full Display format can be seen in the sample run for test1.cpp linked below under "Test Programs".
    For description of the path setting, see the funtion TogglePath() below
  • TogglePath()
    This function, when called, should reverse whatever the current "path" setting is. The path setting can be either ON or OFF. If it's ON, it means that displays of the grid should indicate where the mover has been by showing those positions as spaces. If the path is OFF, then all blank spots on the grid show as the dot character '.' no matter what. The initial default setting for any grid should be ON.
  • Simple Accessors (Getters)
    These are "getter" functions that should return the requested information:
    • GetRow() should return the current row of the mover
    • GetCol() should return the current column of the mover
    • GetNumRows() should return the number of rows in the grid
    • GetNumCols() should return the number of columns in the grid
  • Predicate functions
    These two functions return boolean values (true or false) to answer simple questions:
    • FrontIsClear() should return an indication of whether the space in front of the mover is clear (i.e. not blocked and on the grid)
    • RightIsClear() should return an indication of whether the space to the right of the mover is clear (i.e. not blocked and on the grid)
  • Placing blocks and/or items
    These functions involve placing things on the grid:
    • PutDown(): This function should place an "item" at the current location of the mover. If the location already contains an item, then nothing changes (i.e. the item is still there)
    • PutDown(int r, int c): This function should place an "item" at position (r,c) where r is the row and c is the column. This function should return true for a successful placement, and false for failure. For successful placement, the position has to exist within the grid boundaries and not already contain a block or another item. (It can, however, be placed in a spot where only the mover is located).
    • PlaceBlock(int r, int c): This function should place a "block" at position (r,c) where r is the row and c is the column. This function should return true for a successful placement, and false for failure. For successful placement, the position has to exist within the grid boundaries and be an empty space (i.e. not containing a block, an item, or the mover)
  • PickUp()
    This function should pick up the "item" at the mover's position. This means removing it from the grid. This function should return true for a successful pick-up (i.e. the item is at the mover's current position), and false for failure (there is no item there).
  • Move(int s)
    This function should move the mover forward, in the current direction, for s spaces. Return true for success, false for failure. A successful move must be a positive number of spaces, must remain on the grid, and must not attempt to move through a "block". On a failed move, the mover should remain in the original position. (i.e. the move must be all or nothing, based on the number of spaces given by the parameter).
  • TurnLeft()
    This function will cause the mover to turn 90 degrees to the left, from whichever way it is currently facing. (example: if the mover is facing NORTH, then TurnLeft() will make it face WEST).
  • void Grow(int gr, int gc)
    This function should increase the size of the grid by gr rows and gc columns. If the increase causes either the number of rows or columns to exceed the maximum, simply set that (rows or columns) to the maximum. The grow should not change the current position of any item, mover, or block on the grid.
  • Note that the list of member functions given in the provided starter file (and described above) constitute the entire public interface of the class. These should be the ONLY public member functions in your class. If you create any extra member functions as helpers, put them in the private section of the class

In: Computer Science

package applications; public class Matrix { private int[][] m; public Matrix(int x, int y) { m...

package applications;

public class Matrix

{

private int[][] m;

public Matrix(int x, int y)

{

m = new int[x][y];

}

public Matrix(int x, int y, int z)

{

m = new int[x][y];

for(int i = 0; i < x; i++)

{

for(int j = 0; j < y; j++)

{

m[i][j] = z;

}

}

}

public int rowsum(int i) throws IndexOutOfBoundsException

{

if (i < 0 || i > m.length-1)

{

throw new IndexOutOfBoundsException("Invalid Row");

}

int sum = 0;

for(int j = 0; j < m[i].length; j++)

{

sum += m[i][j];

}

return sum;

}

public static void main(String[] args)

{

Matrix A = new Matrix(100, 100, 1);

System.out.println(A.rowsum(99));

System.out.println("Done!");

Matrix B = new Matrix(1000, 1000, 1);

System.out.println("Done!");

Matrix C = new Matrix(10000, 10000, 1);

System.out.println("Done!");

}

}

1)add method columnSum(j)

2)add method max() which returns the largest value that contain in the matrix

3)add method trace() i.e., if matrix is not square, then throw error otherwise compute the sum of the entries on the diagnol.

In: Computer Science

Fill in each blank with the correct answer/output. Assume each statement happens in order and that...

Fill in each blank with the correct answer/output. Assume each statement happens in order and that one statement may affect the next statement. Hand trace this code instead of using your IDE. String s = "abcdefghijklmnop"; ArrayList r = new ArrayList(); r.add("abc"); r.add("cde"); r.set(1,"789"); r.add("xyz"); r.add("123"); Collections.sort(r); r.remove(2); The first index position in an array is __________. System.out.print( s.substring(0,1) ); // LINE 2 System.out.print( s.substring(2,3) ); // LINE 3 System.out.print( s.substring(5,6) ); // LINE 4 System.out.print( r.get(0) ); // LINE 5 System.out.print(r.get(0).substring(0,1)); // LINE 6 System.out.print( r.get(2) ); // LINE 7 System.out.print( r.indexOf("123")); // LINE 8 System.out.print( r.contains("abc")); // LINE 9 System.out.print( r.isEmpty()); // LINE 10 r.set(1, "\\\\"); System.out.print(r); // LINE 11 r.remove(1); System.out.print(r); // LINE 12 r.add("one"); System.out.print(r); // LINE 13 r.add(0,"five"); System.out.print(r); // LINE 14 r.clear(); System.out.print(r); // LINE 15 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.

In: Computer Science

_______ are small central processing units chips. in the expression 12.45 + 3.6, the values to...

_______ are small central processing units chips.

in the expression 12.45 + 3.6, the values to the right and left of the + symbol are the______

python uses______ to categorize values in memory.

the% symbol is the remainder operator. also known as the______ operator.

when applying the .3f formatting specifier er to the number 76.15854, the result is____.

In: Computer Science

Assume a byte-addressable memory has 64K bytes. Blocks are 8 bytes in length and the cache...

Assume a byte-addressable memory has 64K bytes. Blocks are 8 bytes in length and the cache consists of 4K bytes. Show the format for a main memory address assuming a 4-way set associative cache mapping scheme. Include the field names as well as their sizes.

In: Computer Science

Write a java script function that accepts integer array as input, and display a new array...

Write a java script function that accepts integer array as input, and display a new array by

performing fol

lowing modifications,

The values in odd index positions must be incremented by 1

The values in even index positions must be decremented by 1.

Assume the array index starts from 0.

Input 1: arr = [1,2,3,4]

Output 1: arr = [0,3,2,5

it done html and javascript and plz do it in simple way

In: Computer Science

Create a class called triangle_area. The initializing inputs are numbers b and h. In addition to...

Create a class called triangle_area. The initializing inputs are numbers b and h. In addition to the initialization method, the class must have the area method, which calculates the area of ​​a triangle (A = b x h / 2) and creates an attribute called Area with that value.

Use python sintaxis

In: Computer Science

Instructions Write a program to implement the algorithm that you designed in Exercise 19 of Chapter...

Instructions

Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1.

Your program should allow the user to buy as many items as the user desires.

Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience.

TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING)

C++ CODE

Exercise 19

Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling is free; otherwise, the shipping and handling is $10 per item. Design an algorithm that prompts Jason to enter the number of items ordered and the price of each item. The algorithm then outputs the total shipping and handling fee, and the billing amount. Your algorithm must use a loop (repetition structure) to get the price of each item. (For simplicity, you may assume that Jason orders no more than five items at a time.)

An example of the program is shown below:

Enter the number of items ordered: 3

Enter the price of item no. 1: 79.00

Enter the price of item no. 2: 23.50

Enter the price of item no. 3: 1.99

The shipping and handling fee is: $30.00
The billing amount is: $134.49

Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.

In: Computer Science

10.5 LAB: Air-traffic control (queue using a linked list) Given a partial main() and PlaneQueue class,...

10.5 LAB: Air-traffic control (queue using a linked list)

Given a partial main() and PlaneQueue class, write the push() and pop() methods for PlaneQueue. Then complete the main() to read in whether flights are arriving or have landed at an airport. An "arriving" flight is pushed onto the queue. A "landed" flight is popped from the front of the queue. Output the queue after each plane is pushed or popped. Entering -1 exits the program.

Ex: If the input is:

arriving AA213
arriving DAL23
arriving UA628
landed
-1

the output is:

Air-traffic control queue
   Next to land: AA213

Air-traffic control queue
   Next to land: AA213
   Arriving flights: 
      DAL23

Air-traffic control queue
   Next to land: AA213
   Arriving flights: 
      DAL23
      UA628

AA213 has landed.
Air-traffic control queue
   Next to land: DAL23
   Arriving flights: 
      UA628

AirTrafficControl.java

import java.util.Scanner;

public class AirTrafficControl {

public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
  
PlaneQueue planeQueue = new PlaneQueue();
  
PlaneNode curNode;
PlaneNode foundNode;
String arrivingOrLanded;
String flightCode;
  
// TODO: Complete main to read in arriving flight codes and whether
// a flight has landed. Print the queue after every push() or
// pop() operation. If the user entered "landed", print which
// flight has landed. Continue until -1 is read.
  
}
}

PlaneQueue.javapublic class PlaneQueue {
private PlaneList planeList; // Queue implemented using linked list
int length;

public PlaneQueue() {
planeList = new PlaneList();
length = 0;
}

// TODO: Write push() and pop() methods. push() adds an item to
// the queue and increases the length by 1. pop() removes and
// returns the first item in the queue and decreases the length by 1.

public boolean isEmpty() {
if (length == 0) {
return true;
}
return false;
}

public int getLength() {
return length;
}

public void printPlaneQueue() {
PlaneNode curNode;

curNode = planeList.headNode;
System.out.println("Air-traffic control queue");
if (!isEmpty()) {
System.out.print(" Next to land: ");
curNode.printNodeData();
System.out.println();
  
if (length > 1) {
System.out.println(" Arriving flights: ");
curNode = curNode.nextNode;
while (curNode != null) {
System.out.print(" ");
curNode.printNodeData();
System.out.println();
curNode = curNode.nextNode;
}


}
}
  
else {
System.out.println("Queue is empty.\n");
}
System.out.println();
}
}

PlaneList.java

public class PlaneList {
// Linked list nodes
public PlaneNode headNode;
public PlaneNode tailNode;

public PlaneList() {
// Front of nodes list   
headNode = null;
tailNode = null;
}

// append
public void append(PlaneNode newNode) {
if (headNode == null) { // List empty
headNode = newNode;
tailNode = newNode;
}
else {
tailNode.nextNode = newNode;
tailNode = newNode;
}
}

// prepend
public void prepend(PlaneNode newNode) {
if (headNode == null) { // list empty
headNode = newNode;
tailNode = newNode;
}
else {
newNode.nextNode = headNode;
headNode = newNode;
}
}

// insertAfter
public void insertAfter(PlaneNode curNode, PlaneNode newNode) {
if (headNode == null) { // List empty
headNode = newNode;
tailNode = newNode;
}
else if (curNode == tailNode) { // Insert after tail
tailNode.nextNode = newNode;
tailNode = newNode;
}
else {
newNode.nextNode = curNode.nextNode;
curNode.nextNode = newNode;
}
}

// removeAfter
public void removeAfter(PlaneNode curNode) {
PlaneNode sucNode;
  
// Special case, remove head
if (curNode == null && headNode != null) {
sucNode = headNode.nextNode;
headNode = sucNode;

if (sucNode == null) { // Removed last item
tailNode = null;
}
}
else if (curNode.nextNode != null) {
sucNode = curNode.nextNode.nextNode;
curNode.nextNode = sucNode;

if (sucNode == null) { // Removed tail
tailNode = curNode;
}
}
}

// search
public PlaneNode search(String key) {
PlaneNode curNode;
int position = 1;
  
curNode = headNode;
while (curNode != null) {
curNode.nodePos = position;
if (curNode.flightCode.equals(key)) {
return curNode;
}
curNode = curNode.nextNode;
++position;
}
return null;
}

public void printPlaneList() {
PlaneNode curNode;

curNode = headNode;
while (curNode != null) {
curNode.printNodeData();
System.out.println();
curNode = curNode.nextNode;
}
}
}

PlaneNode.java

public class PlaneNode {
public String flightCode;
public PlaneNode nextNode; // Reference to the next node
public int nodePos;

public PlaneNode() {
flightCode = "0";
nextNode = null;
}

// Constructor   
public PlaneNode(String initFlightCode) {
this.flightCode = initFlightCode;
this.nextNode = null;
}

// Constructor   
public PlaneNode(String initFlightCode, PlaneNode newNextNode) {
this.flightCode = initFlightCode;
this.nextNode = newNextNode;
}

public void printNodeData() {
System.out.print(this.flightCode);
}
}

In: Computer Science

Thoroughly discuss and answer the following question. Do some research and find out whether Babbage’s Analytical...

Thoroughly discuss and answer the following question. Do some research and find out whether Babbage’s Analytical Engine is a computer according to the von Neumann model. Post a complete answer to the best of your abilities and research and understanding. Reference your sources other than textbook.

In: Computer Science

Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret...

Policy Drivers

The purpose of this assignment is to practice and demonstrate your ability to interpret detailed policy. We have chosen for you to take a look at two of the most well known policies; in real life, you will have government polices such as these as well as enterprise specific policies or regulations. As you build information systems, it is key to early on in the process to identify all relevant policy drivers and understand them.

In the module, we discussed how an organization's policies and regulations for data governance influence the nature and structure of IT/IS systems. For your assignment, research either HIPAA (for health care) or Sarbanes-Oxley (for financial data). In 1 page, describe at least two of the policies you find and explain how an IT/IS system would need to accommodate.

In: Computer Science

Create a Java method that does the following: 1) Ask the user for a dividend and...

Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Please see the videos for the explanation. This is the code I have from the previous work that should be modified to fit this problem:

import java.util.Scanner;

public class DivisionAlgorithm {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int n1, n2;

System.out.print("Enter dividend input: ");

n1 = scanner.nextInt();

System.out.print("Enter divisor input: ");

n2 = scanner.nextInt();

while(n1>=n2){

n1 = n1 - n2;

}

System.out.println("Quotient = "+n1);

}

}

-22 / 3 doesn't compute correctly, negative numbers return with errors.

In: Computer Science

For this assignment you will implememnt a number of Boolean functions, such as implies, nand, etc....

For this assignment you will implememnt a number of Boolean functions, such as implies, nand, etc.

a) Boolean functions You are provided with a set of undefined functions.You will create the bodies for these 2 parameter functions, such that they return the appropriate Boolean value (True or False). The formal parameters are always p and q (in that order)

Notice the difference between npIMPnq and nqIMPnp: In npIMPnq you return not p implies not q (not first param implies not second param), for example npIMPnq(True,False) returns True.

In nqIMPnp you return not q implies not p (not second param implies not first param), for example nqIMPnp(True,False) returns False.

b) Truth-table inputs The function makettins(n) will create a truth table for all combinations of n Boolean variables. A truth table is an arrayList of 2**n arrayLists of n Booleans. For example makettins(2) returns
[[False, False], [False, True], [True, False], [True, True]]

Notice the recursive nature of makettins(n): It consists of a truth-table(n-1), each row prefixed with False followed by the same truth-table(n-1), each row prefixed with True, with a base case for n==1: [[False], [True]]

Two functions are provided: run(f) and main, so that you can test your code.

'''
PA1: Boolean functions and truth-table inputs
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

For PA1 you will implememnt a number of Boolean functions,
such as implies, nand, etc.

a) Boolean functions
You are provided with a set of undefined functions.You will
create the bodies for these 2 parameter functions, such that
they return the appropriate Boolean value (True or False).
The formal parameters are always p and q (in that order)

Notice the difference between npIMPnq and nqIMPnp:
In npIMPnq you return not p implies not q (not first
param implies not second param), for example
npIMPnq(True,False) returns True.

In nqIMPnp you return not q implies not p (not second
param implies not first param), for example
nqIMPnp(True,False) returns False.

b) Truth-table inputs
The function make_tt_ins(n) will create a truth table for
all combinations of n Boolean variables. A truth table is
an arrayList of 2**n arrayLists of n Booleans. For example
make_tt_ins(2) returns
[[False, False], [False, True], [True, False], [True, True]]

Notice the recursive nature of make_tt_ins(n):
It consists of a truth-table(n-1), each row prefixed with False
followed by the same truth-table(n-1), each row prefixed with True,
with a base case for n==1: [[False], [True]]

Two functions are provided: run(f) and main, so that you can test
your code.

python3 PA1.py tests your Boolean function
python3 PA1.p=y tt tests your function make_tt_ins()

'''


import sys

# p implies q
def implies(p, q):
return False
# not p implies not q
def npIMPnq(p,q):
return False

# not q implies not p
def nqIMPnp(p,q):
return False

# p if and only if q: (p implies q) and (q implies p)
def iff(p, q):
return False

# not ( p and q )
def nand(p, q):
return False

# not p and not q
def npANDnq(p,q):
return False

# not ( p or q)
def nor(p, q):
return False

# not p or not q
def npORnq(p,q):
return False

def make_tt_ins(n):

return [[]]

#provided
def run(f):
print(" True,True : ", f(True,True))
print(" True,False : ", f(True,False))
print(" False,True : ", f(False,True))
print(" False,False: ", f(False,False))
print()
  
#provided
if __name__ == "__main__":
print("program", sys.argv[0])
f1 = sys.argv[1]
print(f1);
if(f1 == "implies"):
run(implies);
if(f1 == "iff"):
run(iff)
if(f1 == "npIMPnq"):
run(npIMPnq)
if(f1 == "nqIMPnp"):
run(nqIMPnp)
if(f1 == "nand"):
run(nand)
if(f1 == "nor"):
run(nor)
if(f1 == "npANDnq"):
run(npANDnq)
if(f1 == "npORnq"):
run(npORnq)
if(f1 == "tt"):
print(make_tt_ins(int(sys.argv[2])))
  

In: Computer Science