Changes

Jump to: navigation, search

OPS435 Python Lab 3

71 bytes removed, 08:36, 31 May 2017
PART 1 - Using Functions
</source>
'''Functions and Numbers (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!
print(number + 5)
print(return_number_value() + 10)
</source> What do you notice?<br><br> You should notice a warning message. This occurs because the returning value is a '''stringnumber''' and not NOT a '''numberstring'''! By the way, similar issues can occur when mixing up Combining numbers and strings and numbers in other programming languages a statement (such as '''print(for example: JavaScript)''') can cause errors. The error message should appear similar to the one displayed below: <source>
number = return_number_value()
print('my number is ' + number)
TypeError: Can't convert 'int' object to str implicitly
</source>
:#If a number needs to be combined with a string, use the '''str() ''' predefined function that was discussed in a previous lab in order to convert the returned string number into a number to be the one of the following syntax below.string:<source>
number = return_number_value()
print('my number is ', number)
13,420
edits

Navigation menu