Functions, Arguments, and Return Values

Today introduces you to the concept of calling functions in order to run other code. We discuss how to call functions, how to pass arguments, and what functions return.

Read Chapter 4

Read just the first 3 small sections of Chapter 4 of your online textbook.

Today in Class

We will discuss and learn about:

You should be able to understand this program.

    print("Enter a time hh,mm,ss")
hours = input()     # Does input() require an argument?
mins = input()
seconds = input()

total = 3600*int(hours) + 60*int(mins) + int(seconds)

print("Elapsed time is" + str(total) + "seconds.", end='')  # what does end do?

And this one with different operator + usage:

print("Hello let's talk about types!")
x = 5
y = 6
result = x + y
print(result)
x = '5'
y = '6'
result = x + y
print(result)
print("Why did this happen?")
print("Ok let's try again.")
result = int(x) + int(y)
print(result)
print("What do you think?")

Try running it!

Copy the above into a test.py program in VSCode and give it a run!

Make sure you understand why the output is how it is. Then play around with it. For instance, what happens if you change the + to a multiply * ?