Problem 4 – makeScarf(scarf)
Let’s knit a scarf! With Python today we are knitting recursively.

Your main program should be contained in a recursive function called makeScarf() which takes
a string: your scarf that will be printed out in the end. You may use other helper functions as
needed, but you may NOT store the scarf in a global variable outside of any function. Notice that the function header uses a default parameter value of “” for the scarf. This allows you to call the function like this: makeScarf() passing in no argument for the scarf parameter. The function will automatically use the empty string “” as the default value for the scarf parameter in this case.

Your function should start by displaying a menu like this:
Scarf Menu:
s - new section
d - new decorated section
f - fringe
q – quit
What would you like to do?

If the answer is not a valid option, display an error message and display the menu again by
calling makeScarf(scarf) again.

If the answer is s, add on a new undecorated section to your scarf, print out the scarf as it is so far, and then display the menu again.

If the answer is d, add on a decorated section to your scarf, print out the scarf as it is so far, and then display the menu again.

If the answer is f, add fringe to the top AND bottom of your scarf, print the final scarf and end the program.

If the answer is q, print the final scarf and end the program.

To start your program, you call makeScarf(). (The default parameter will automatically give your initial scarf the empty string value. When you make your recursive calls from inside your function, make the calls like this: makeScarf(scarf) so that the scarf you have built so far continues to be used.)


Sample output:

>>> makeScarf("")
Scarf Menu:
s - new section
d - new decorated section
f - fringe
q - quit
What would you like to do? s
-----
| |
| |
| |
-----
Scarf Menu:
s - new section
d - new decorated section
f - fringe
q - quit
What would you like to do? d
-----
| |
| |
| |
-----
-----
|\/\|
|/\/|
|\/\|
|/\/|
-----
Scarf Menu:
s - new section
d - new decorated section
f - fringe
q - quit
What would you like to do? s
-----
| |
| |
| |
-----
-----
|\/\|
|/\/|
|\/\|
|/\/|
-----
-----
| |
| |
| |
-----
Scarf Menu:
s - new section
d - new decorated section
f - fringe
q - quit
What would you like to do? f
|||||
-----
| |
| |
| |
-----
-----
|\/\|
|/\/|
|\/\|
|/\/|
-----
-----
| |
| |
| |
-----
|||||

This is what i have but i really have no idea what im doing or where to go. ive been messing around with it but could really use some help. i just started the course last week!
def makeScarf(scarf):
print """
Scarf Menu:
s - new section
d - new decorated section
f - fringe
q - quit
"""
return int(raw_input("What would you like to do?"))

def makeScarf():
choice = makeScarf(scarf)
if choice == s:
print ()
print "----- "
print" | |"
print "| |"
print "| |"
print" -----"
print makeScarf(scarf)
elif choice == d:
print ()
print "----- "
print" |\/\|"
print "|/\/|"
print" |\/\|"
print "|\/\|"
print" -----"
print makeScarf(scarf)
elif choice == f:
print "|||||"
print (scarf)
print "|||||"
print makeScarf(scarf)
elif choice == q:
print ()

Try this one out hope this suits your requirement

import sys
clist = []
def makeScarf():
  print """
  Scarf Menu:
  s - new section
  d - new decorated section
  f - fringe
  q - quit
  """
  return raw_input("What would you like to do?: ")

def checkScarf():
  choice = makeScarf()
  clist.append(choice)
  for entry in clist :  
    if entry == "s":
        print "-----"
        print "| |"
        print "| |"
        print "| |"
        print "-----"
    elif entry == "d":
        print "----- "
        print "|\/\|"
        print "|/\/|"
        print "|\/\|"
        print "-----"
    elif entry == "f":
        print "----- "        
        print "|||||"
        print "|||||"
        print "|||||"
        print "----- "
    elif entry == "q":
        sys.exit()
  checkScarf()
checkScarf()

How would you do this using a while loop?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.