181,647 views
25 votes
25 votes
My uh coding teacher would like the class to do little piggy with code.

Write code using def to create functions so that each line is printed in its own function. Turn in a gdb link so I can grade it.


This little pig went to the market.

This little pig stayed home.

This little pig had roast beef.

This little pig had none.

This little pig cried wee wee wee all the way home.


here's a example from him but i don't understand it


import time


def myFunction():

print('In the function called my function')

time.sleep(2)


def yourFunction():

print('In the function called your function')

time.sleep(2)


#*********MAIN**********

print ('In the main part of the program')

time.sleep(2)

myFunction()

print ('Back in the main')

time.sleep(2)

yourFunction()

print ('Back in the main after your function')


please help if you can

User Chronial
by
3.4k points

1 Answer

15 votes
15 votes

Answer:

see picture below

Step-by-step explanation:

I added a parameter to factor out the first bit of each sentence into a global variable. If you change for example 'pig' into 'monkey', all sentences will change.

My uh coding teacher would like the class to do little piggy with code. Write code-example-1
User Clelia
by
3.2k points