Code Club – Python functions 2

So to follow the previous post, we are going to look at passing 2 arguments to a function, adding them together, then displaying the result.

Firstly open a new Python Trinket

Firstly we are going to tell the interpreter to use python3.

#!/usr/bin/env python3 #use python 3

Now we create a function to take two arguments and display the sub of both

def add_numbers(x,z):
  add = (int(x) + int(z))
  print ('Total = ')

Get user input

x = input("First Number") # ask for first number
z = input("Second Number") # ask for second number

Convert to integers


Call function and pass values to function




MastodonPeertubeQoto sign up


Donate using Liberapay