Difference between revisions of "CSC111 Python Programs Fall 2015"

From dftwiki3
Jump to: navigation, search
(Wed. Sept. 16, 2015)
Line 20: Line 20:
  
 
</source>
 
</source>
 
+
<br />
 +
=Friday, 9/18/15=
 
<br />
 
<br />
 
<source lang="python">
 
<source lang="python">
Line 36: Line 37:
  
 
# user input.  Get info from user
 
# user input.  Get info from user
fName = "Dominique"
+
fName = "Al"
lName = "Thiebaut"
+
lName = "K"
Id    = 990123456
+
Id    = "990123456"
 
final = 90
 
final = 90
  
# format information and display
+
 
 +
#--- Format information and display ---
 +
# create the bar
 
bar = "+" + 48*"-" + "+"
 
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( bar )
print( "|", fName, lName, Id, "|" )
+
print( "|" + fName, lName, spaces, Id, "|" )
 
print( bar )
 
print( bar )
print( final )
+
print()
print( classAvg )
+
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) * "#" )
  
 
</source>
 
</source>

Revision as of 12:28, 18 September 2015

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


Wed. Sept. 16, 2015


# 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) * "#" )