CSC111 Programs Created in Class 2018
D. Thiebaut (talk) 12:30, 31 January 2018 (EST)
Contents
1/30/18
# wedWeek1.py
# D. Thiebaut
# Demo program week 1
# variables
age = 20
year = 2018
# compute year born
print( year - age )
# example of for loop
for name in [ "smith", 23, 3.14159, "hello" ]:
print( name )
"""
challenge: print the following lines
***
Mae
*****
Alice
*******
Felicia
"""
for name in [ "Mae", "Alice", "Felicia" ]:
print( '*' * len( name ) )
print( name )
"""
new challenge: print the following lines
*
Mae
********
Alice
****
Felicia
**
"""
for name in [ "*", "Mae", "********", "Alice", "****", "Felicia", "**" ]:
print( name )
02/05/18
Table of Fahrenheit to Celsius conversion
# 020518.py # D. Thiebaut # # print table of temperatures # start at 100 F down to -30 F # in steps of 10 # using the formula: Celsius = (Farhenheit - 32 ) * 5 / 9 # print the header print( "Fahrenheit --> Celsius" ) # display the table of temperatures # ranging from 100 down to -30F. for fTemp in range( 100, -31, -10 ): cTemp = ( fTemp - 32 ) * 5 / 9 print( fTemp, '-->', cTemp )
Problem: get user name and grade and display user information and grade as a bar graph.
# barGraph.py
# D. Thiebaut
# this program prompts the user for her information
# and grade and displays a bar-graph.
#
#First name? Dominique
#Last name? Thiebaut
#Id? 990123456
#Final grade? 90
#
#+———————————————————————————————————-———————————-+
#|Dominique Thiebaut 990123456 |
#+———————————————————————————————————-———————————-+
# 00...10...20...30...40...50...60...70...80...90...100
#grade: #############################################
#class: ########################################
#
#
# input section
fName = input( "First name? " )
lName = input( "Last name? " )
Id = input( "Id? " )
final = input( "Final grade? " )
# output section
print( fName, lName, Id )
bar = "+———————————————————————————————————-———————————-+"
barLen = len( bar )
print( "barLen =", barLen )
nameIdLen = len( fName )+1+len( lName ) + len( Id )+1
print( "nameIdLen =", nameIdLen )
print( bar )
print( "|", fName, lName, ' '*(barLen-nameIdLen), Id, '|' )
print( bar )
2/7/18
# chessBoard.py # D. Thiebaut # displays an 8x8 chessboard, as shown below. """ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### """ numRows = eval( input( "Number of rows? " ) ) numCols = eval( input( "Number of columns? " ) ) white=" " black="###" bar1 = "" bar2 = "" for i in range( numCols//2 ): bar1 = bar1 + white + black bar2 = bar2 + black + white for i in range( numRows//2 ): # display 2 lines of squares # alternating the colors # 5 ### ### ### ### # ### ### ### ### # ### ### ### ### # ### ### ### ### # ### ### ### ### # ### ### ### ### for n in range( 3 ): print( bar1 ) for n in range( 3 ): print( bar2 )