CSC111 Python Programs Fall 2015

From dftwiki3
Revision as of 06:58, 22 September 2015 by Thiebaut (talk | contribs) (Monday, 9/21/15)
Jump to: navigation, search

--D. Thiebaut (talk) 10:34, 18 September 2015 (EDT)


Wed., 9/16/15


# displayWeek.py
# D. Thiebaut
# displays a schedule for the five days of the week

length = eval( input( "Length of bar? " ) )

print( "-" * length )
for day in [ "Mo:", "Tu:", "We:", "Th:", "Fr:" ]:
    print( day )
    #print( "  :" * 2)
    print( "  :" )
    print( "-" * length )


Friday, 9/18/15


# displayGrade.py
# D. Thiebaut
#
# prompts user for information and
# grade.
# display user's grade in graph, along with
# class average (constant)


# constant information
classAvg = 80

# user input.  Get info from user
fName = "Al"
lName = "K"
Id    = "990123456"
final = 90


#--- Format information and display ---
# create the bar 
bar = "+" + 48*"-" + "+"
lenBar = len( bar )

# compute the number of dashes
noSpaces = lenBar - len( fName ) -len(lName )-len(Id) - 6
spaces = " " * noSpaces

# create the scale
scale = "      00...10...20...30...40...50...60...70...80...90...100"

# display the information
print( bar )
print( "|" + fName, lName, spaces, Id, "|" )
print( bar )
print()
print( scale )
# the length of the bar for the bar-graph, in number of characters
# is 1/2 the actual grade.  So divide the grade by half to get the
# number of chars.  We use // to get the integer part of the result
print( "grade:", (final//2) * "#" )
print( "class:", (classAvg//2) * "#" )


Monday, 9/21/15


Version 1 of Teller Machine program

# tellerMachine.py
# D. Thiebaut
# A program that simulates a teller machine, where user enters an amount of
# dollars, and program figures out the number of bills to return.

# get the amount 
amount = eval( input( "Please enter amount: " ) )
amount = int( amount )
print()

# break down into bills
no20s = amount // 20       # how many 20s go into amount
amount = amount % 20    # what is left over after giving out 20s go back into amount

no10s = amount // 10
amount = amount % 10

no5s = amount //5
no1s = amount % 5

# display the results
print( "Amount withdrawn = ", amount )
print( "Please lift your keyboard and find: " )
print( no20s, "$20-bill(s)" )
print( no10s, "$10-bill(s)" )
print( no5s, "$5-bill(s)" )
print( no1s, "$1-bill(s)" )


Version 2, submitted by Shirui Cheng, who figured out that it was a perfect opportunity to use a loop!

# Teller machine simulator
# Shirui Cheng

# get the input
amount = eval(input ("How much money do you want to withdraw? "))

# break down in $20-, $10-, $5-, and $1-bills
# and print the result at every step
for bill in (20, 10, 5, 1):
    no = amount // bill
    amount = amount % bill
    print (no, "$", bill, "bill(s)")