Changes

Jump to: navigation, search

OPS435 Python Lab 3

36 bytes added, 10:24, 2 June 2017
PART 1 - Providing Functions With Arguments
ipython3
</source>
:#Now try making some functions that uses if statements, '''BUT BEWARE''', making an if statement inside a Define the following function means that you are indented two times to get to the if statement.in your ipython shell:<source>
def check_temperature(temp):
if temp > 30:
elif temp == 20:
return 'perfect'
return 'ok' </source>'''FYI:#''' Remember to note the extra indentation on the that you MUST consistently '''indent ALL code under ''' for within each logic section (or test): otherwise, it may not allow the if statementslogic statement to work correctly. The final '''return "ok"''' will only take place if a previous return has not taken place before it. Once return has been used in a function, the function immediately exits and returns the value. :#Issue the following functions (with arguments) to confirm the results:<source>
check_temperature(50)
'hot'
 
check_temperature(20)
'perfect'
 
check_temperature(-50)
'cold'
 
check_temperature(25)
'ok'
 
check_temperature(10)
'ok'
13,420
edits

Navigation menu