Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

351 bytes added, 08:30, 31 May 2017
PART 1 - Using Functions
'''Functions and Integers'''
: You will now learn how to define and run functions that will return '''integer data''' when a function is called.In this section, you will define a function that will be returning integer values instead of text. There is not a big difference, but when returning number values, care needs to be taken if you try combining it with a string!
:'''Perform the Following steps:'''
:#In this next example Issue the functions will be returning integer values instead of text. There is not a big difference, but when returning number values, care needs to be taken if you try combining it with a string.following in your ipython3 shell:<source>
def return_number_value():
num1 = 10
</source>
:#Now try storing , issue the return value of following in the above ipython3 shell to call the '''return_number_value()''' function.:<source>
number = return_number_value()
print(number)
print(number + 5)
print(return_number_value() + 10)
</source>:#The What do you notice?<br><br> You should notice a warning again, message. This occurs because this the returning value is a '''string''' and not a '''number value'''! By the way, using it with similar issues can occur when mixing up strings can cause errorsand numbers in other programming languages (for example: JavaScript). The error message should appear similar to the one displayed below: <source>
number = return_number_value()
print('my number is ' + number)
13,420
edits