Select Page

ABIOLA RASP – Raspberries for African School Projects

Wie können wir helfen?

< Alle Themen
Print

Python – Functions with parameter

no-168 au-03

Functions

If you send a parameter to functions, it returns different results depending on the parameters.

Please see the article “Python – First Program” how to open Thonny Python IDE and how to save your work.

  1. fullName function gets two string parameters and prints these parameters.
  2. sumNumbers function gets two integer parameters and prints the sum of these integers.
  3. Call fullName functions with two string parameters. (“Max”, “Neuer”)
  4. Call sumNumbers functions with two integer parameters. (3, 5)
  5. Call fullName functions with two string parameters. (“Harry”, “Seaman”)
  6. Call sumNumbers functions with two integer parameters. (15, 20)
  7. Click Run button.
  8. Here is the result.

Code:
def fullName(firstName, secondName):     
print(“My name ist ” + firstName + ” ” + secondName) 
def sumNumbers(num1, num2):   
print(“The sum of number is ” + str(num1 + num2))   

fullName(“Max”, “Neuer”)
sumNumbers(3, 5)
fullName(“Harry”, “Seaman”)
sumNumbers(15, 20)

Inhaltsverzeichnis