Contents

  1. ascii_table.py
  2. demo_str.py
  3. escape_sequence.py
  4. format_examples.py
  5. sales_tax2.py
  6. sales_tax.py
  7. temp_table.py

ascii_table.py 1/7

[
top][prev][next]
# Create a table of numbers (ASCII) and their character equivalent.
# by Sara Sprenkle

print("This program prints out part of the ASCII Table")
print("The ASCII value is followed by the character.")

print("DEC CHAR")
print("-"*3, "-"*4)

for i in range(33, 127):
    print("{:3d} {:>4s}".format(i, chr(i)))
    

demo_str.py 2/7

[
top][prev][next]
# Demonstrate long strings and escape sequences
# by Sara Sprenkle

string = """This is a long string.
Like, really long.
Sooooo loooooong"""

print(string)

print("To print a \\, you must use \"\\\\\"")


escape_sequence.py 3/7

[
top][prev][next]
# Practice with escape sequences
# CS111

# Display To print a tab, you must use '\t'.
# If you use double quotes, you don't _need_ to escape the single quote
print("To print a tab, you must use a '\\t'.")
print('To print a tab, you must use a \'\\t\'.')

# Display I said, "How are you?"
print("I said, \"How are you?\"")
print('I said, "How are you?"')


format_examples.py 4/7

[
top][prev][next]
# Formatting examples, from handout
# CSCI111

x = 10
y = 3.5
z = "apple"
print("{:6d}".format(x))
print("{:6.2f}".format(x))
print("{:6.2f}".format(y))
print("{:06.2f}".format(y))
print("{:+6.2f}".format(y))
print("{:^10s}".format(z))
print("*{:^10s}*".format(z))
print("{:5d} {:<7.3f}".format(x,y))

sales_tax2.py 5/7

[
top][prev][next]
# Compute the cost of an item, plus sales tax.
# The displayed cost uses a format specifier.
# by Sara Sprenkle

SALES_TAX=.053  # the sales tax in VA

value = eval(input("How much does your item cost? "))

with_tax = value * (1+SALES_TAX)

print("Your item that cost ${:.2f}".format(value), end=' ')
print("costs ${:.2f} with tax".format(with_tax))

sales_tax.py 6/7

[
top][prev][next]
# Compute the cost of an item, plus sales tax
# Demonstrate need for/use of format specifiers
# by Sara Sprenkle

SALES_TAX=.053  # the sales tax in VA

# Test with a variety of values
value = eval(input("How much does your item cost? "))

with_tax = value * (1+SALES_TAX)

print("Your item that cost $", value, end=' ')
print("costs $", with_tax, "with tax.")

temp_table.py 7/7

[
top][prev][next]
# Print out the table of temperatures
# By CS111

# Better to calculate these conversions but that's not the focus today
ftemp = -459.67
ctemp = -273.15
ktemp=0


ftemp = 0
ctemp = -17.77778
ktemp= 255.222



ftemp = 32
ctemp = 0
ktemp= 273.15

Generated by GNU Enscript 1.6.6.