Difference between revisions of "CSC111 Programs Created in Class 2018"

From dftwiki3
Jump to: navigation, search
(Created page with "~~~~ ---- =1/30/18= <source lang="python"> # wedWeek1.py # D. Thiebaut # Demo program week 1 # variables age = 20 year = 2018 # compute year born print( year - age ) #...")
 
Line 51: Line 51:
 
     print( name )
 
     print( name )
 
      
 
      
 +
</source>
 +
 +
=02/05/18=
 +
<br />
 +
==Table of Fahrenheit to Celsius conversion==
 +
::<source lang="python">
 +
# 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 )
 +
   
 +
</source>
 +
==Problem: get user name and grade and display user information and grade as a bar graph.==
 +
<source lang="python">
 +
# 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 )
 +
 +
 
</source>
 
</source>

Revision as of 12:21, 5 February 2018

D. Thiebaut (talk) 12:30, 31 January 2018 (EST)


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 )