Output Formatting and Boolean Expressions

Reading

2. Variables, expressions and statements


Most Important Concepts

  • Output can be formatted to two decimal places with format(variableName, '.2f')

  • sep - can override space from comma

  • end - can override newline at end of print

  • Python Numbers, Type Conversion and Mathematics

  • Boolean - true or false

  • Truth table - A table showing all possible input values and the associated output values - Truth Tables

  • The computer only knows numbers. Letters are encoded. ASCII Table and Description

  • You can output the result of a boolean comparison like print(x < y) or print(x < y and y < z)

  • You should always have a complete expression that evaluates to true or false on both sides of an and or or

Sample Program

# Prof. Vanselow

# An integration of everything I have learned about programming

print("Welcome to my Integration Project!")


print("1. Calculate Area")

# side is a variable

# a variable is a name for a location in memory

side = int(input("Enter the length of the side of a square to get the area:"))

area = side * side

print(area)

# You could also do print(side * side)


print("2. Output formatting")

print("Output can be formatted to two decimal places with format(variable_name, '.2f')")

price = 599.9999

print("For example, 599.999 becomes:", format(price, '.2f'))


print("Exiting.")