Difference between revisions of "Add Area"

From CompSciWiki
Jump to: navigation, search
 
m
Line 6: Line 6:
 
Example:
 
Example:
 
<BR>
 
<BR>
combineNumber(204, 8998810);
+
combineNumber(204, 8998810)
 
<BR><BR>
 
<BR><BR>
 
Output:
 
Output:

Revision as of 01:22, 4 April 2012

Back to the Program-A-Day homepage

Problem

Write a function that has two parameters. It will return the conbination of the two parameters.

Example:
combineNumber(204, 8998810)

Output:
2048998810

 

Introducing Functions

Solution

The skeleton structure will be like this

 def combineNumber(areaCode, phoneNumber):

  return result
def main():

main() 

We can start to write the combineNumber function

 def conbineNumber(areaCode, phoneNumber):
  areaCode = areaCode * 10000000
  result = areaCode + phoneNumber
  return result 

We can finish the main function

 def main():
  temp = combineNumber(204, 8998810)
  print temp
main() 

Code

Solution Code

Back to the Program-A-Day homepage