Python:: Easy lab

profileLLLLEE
hint2.pdf

CSE 5120 March Programming Assignment “The printing parts”

Kerstin Voigt, March 2021

In the Python interpreter shell:

Type an variable + enter: the interpreter will display the value of this variable

… this can look messy for values that are large data structures …

Using Python 3 print to print out the value does not produce any better looking output

messy!

still messy…

Plain Python print(…) is fine for simple values or simple, moderately sized data structures

It you want a data structure to be printed more “neatly aligned”, e.g., in some pseudo tabular form, WE WRITE OUR OWN FUNCTIONS

Note: the only reason that print_table has a second parameter ‘_’, is because my original print_table was a bit more elaborate and took two arguments; to blend with the existing code, the above print_table has been given a “dummy” second argument; by making it ‘_’, it is anonymous, just a placeholder.

To clean things up, remove ‘_’ and remove second argument from print_table calls in the rule learner code … if you want …

def report_rules(rules): …

def report_covers_neg(dtab,rule): … see 6.2 annotated slides …

Plain Python 3 print of a simple string.

Python 3 “formatted” print; printing of a string with parameters; simplest pattern: the ith {} appearing in the string will be replaced with the ith parameter in .format(…).

Numerous formatting option exist, to be set within {} . See tutorials for details.

Sample Output Behavior of the Rule Learner (1st slide of Module 6.1)

Following instructions, your program output should look similar to this:

  • CSE 5120 March Programming Assignment�“The printing parts”�
  • Slide Number 2
  • Slide Number 3
  • Slide Number 4
  • Sample Output Behavior of the Rule Learner�(1st slide of Module 6.1)