Difference between revisions of "CSC111 Lab 6 2018"
(Created page with "~~~~ ----") |
|||
Line 1: | Line 1: | ||
[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 12:27, 4 March 2018 (EST) | [[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 12:27, 4 March 2018 (EST) | ||
---- | ---- | ||
+ | |||
+ | <bluebox> | ||
+ | This lab deals, once again, with functions. Many functions, some receiving no parameters, some receiving several parameters, some returning nothing, some returning values. | ||
+ | The goal of this lab is for you to feel comfortable creating functions that will perform simple tasks that can vary in | ||
+ | </bluebox> | ||
+ | <br /> | ||
+ | __TOC__ | ||
+ | <br /> | ||
+ | =Problem 1= | ||
+ | <br /> | ||
+ | Write a function (in Idle or in the console) called '''bar()''' that prints a line of 30 #-characters. | ||
+ | |||
+ | >>> bar() | ||
+ | ############################## | ||
+ | |||
+ | <br /> | ||
+ | =Problem 2= | ||
+ | <br /> | ||
+ | Create a new function called '''bar2()''' that receives the number of hash-tags and prints a line of that many #-signs. | ||
+ | |||
+ | |||
+ | >>> bar2( 1 ) | ||
+ | # | ||
+ | >>> bar2( 10 ) | ||
+ | ########## | ||
+ | >>> bar2( 5 ) | ||
+ | ##### | ||
+ | >>> | ||
+ | |||
+ | <br /> | ||
+ | =Problem 3= | ||
+ | <br /> | ||
+ | Create a new function called '''bar3()''' that receives the number of #-signs and how many to print. | ||
+ | |||
+ | >>> bar3( 10, '#' ) | ||
+ | ########## | ||
+ | >>> bar3( 1, 'A' ) | ||
+ | A | ||
+ | >>> bar3( 5, '-o' ) | ||
+ | -o-o-o-o-o | ||
+ | >>> | ||
+ | |||
+ | <br /> | ||
+ | =Problem 4= | ||
+ | <br /> | ||
+ | Modify the for-loop below, replacing the '?' symbols with the appropriate expressions, so that uses the loop prints the series of lines shown. | ||
+ | <br /> | ||
+ | |||
+ | >>> for i in range( ?, ? ): | ||
+ | bar3( ?, '+' ) | ||
+ | |||
+ | |||
+ | + | ||
+ | ++ | ||
+ | +++ | ||
+ | ++++ | ||
+ | >>> | ||
+ | |||
+ | <br /> |
Revision as of 13:41, 4 March 2018
D. Thiebaut (talk) 12:27, 4 March 2018 (EST)
This lab deals, once again, with functions. Many functions, some receiving no parameters, some receiving several parameters, some returning nothing, some returning values. The goal of this lab is for you to feel comfortable creating functions that will perform simple tasks that can vary in
Contents
Problem 1
Write a function (in Idle or in the console) called bar() that prints a line of 30 #-characters.
>>> bar() ##############################
Problem 2
Create a new function called bar2() that receives the number of hash-tags and prints a line of that many #-signs.
>>> bar2( 1 ) # >>> bar2( 10 ) ########## >>> bar2( 5 ) ##### >>>
Problem 3
Create a new function called bar3() that receives the number of #-signs and how many to print.
>>> bar3( 10, '#' ) ########## >>> bar3( 1, 'A' ) A >>> bar3( 5, '-o' ) -o-o-o-o-o >>>
Problem 4
Modify the for-loop below, replacing the '?' symbols with the appropriate expressions, so that uses the loop prints the series of lines shown.
>>> for i in range( ?, ? ): bar3( ?, '+' ) + ++ +++ ++++ >>>