Difference between revisions of "CSC111 Some programs to play with"

From dftwiki3
Jump to: navigation, search
(Created page with "~~~~ ---- <bluebox> Below are some programs to play with on the first day/week of classes. </bluebox> <br /> ::<source lang="python"> age = 20 year = 2015 yearBorn = year - a...")
 
 
Line 8: Line 8:
 
::<source lang="python">
 
::<source lang="python">
 
age = 20
 
age = 20
year = 2015
+
year = 2018
 
yearBorn = year - age
 
yearBorn = year - age
 
   
 
   

Latest revision as of 10:20, 26 January 2018

D. Thiebaut (talk) 10:19, 26 January 2018 (EST)


Below are some programs to play with on the first day/week of classes.


age = 20
year = 2018
yearBorn = year - age
 
print( "you are", age )
print( "you were born in", yearBorn )

# ---------------------------------------------

name = "Alex"
college = "Smith College"
print( name, "goes to", college )

# ---------------------------------------------

for name in  [ "Lea Jones", "Julie Fleur", "Anu Vias" ]:
     print( name )
     print( "———————" )

# ---------------------------------------------

for name in  [ "Lea Jones", "Julie Fleur", "Anu Vias" ]:
     print( name, len( name ) )

# ---------------------------------------------

print( "hello" * 4 )
print( "-" * 10 )
greetings = hello
dash = "-"
print( greetings * 4 )
print( dash * 10 )

# ---------------------------------------------

greetings = "hello"
longGreetings = greeting * 4
print( greetings )
print( longGreetings )

# ---------------------------------------------

for name in  [ "Lea Jones", "Julie Fleur", "Anu Vias" ]:
     bar = len( name ) * "-"
     print( name )
     print( bar )  

# ---------------------------------------------

print( "hello" * 4 )
print( "-" * 10 )

greetings = hello
dash = "-"
print( greetings * 4 )
print( dash * 10 )

# --------------------------------------------- 

greetings = "hello"
longGreetings = greeting * 4
print( greetings )
print( longGreetings )