Contents

  1. demo_str.py
  2. escape_sequence.py
  3. sales_tax2.py
  4. sales_tax.py

demo_str.py 1/4

[
top][prev][next]
# Demonstrate long strings, 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 \"\\\\\""

print "I could print more after this...",
print "See?"


escape_sequence.py 2/4

[
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?"'


sales_tax2.py 3/4

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

SALES_TAX=.05  # 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" % value, end=' ')
print("costs $%.2f with tax" % with_tax)

sales_tax.py 4/4

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

SALES_TAX=.05  # 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 $", value, end=' ')
print("costs $", with_tax, "with tax.")

Generated by GNU enscript 1.6.4.