Python Forum
getting a syntax error and i don't know why
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting a syntax error and i don't know why
#9
It is a docstring, as in "document" string. The computer collects these and uses them when I ask for help.

I like my "ask()" function so much that I decide to use it in other programs. I reorganize function to make it independent of the foods dictionary.
"""survey: Useful function(s) for writing surveys.
"""

def ask(question, items, yes_items, score=1):
    """Ask quesiton.  If input is 'y', add score to each item in yes_items"""
    if input(question) == 'y':
        for item in yes_items:
            items[item] += score

if __name__ == '__main__':
    # Demo code showing how you would use ask()
    foods = {'donuts':0, 'pancakes':0, 'bacon':0, 'waffles':0, 'eggs':0, 'bagels':0}

    print('Please answer each question with "y" for "yes" and "n" for "no".')
     
    # Add one to the foods if you answer yes to these questions
    ask('Do you like food with holes? ', foods, ('donuts', 'bagels'))
    ask('Do you like stuff made from animals? ', foods, ('bacon', 'eggs'))
    ask('Do you like sweets? ', foods, ('donuts', 'pancakes', 'waffles'))
     
    # Subtract 1 from these foods if you are gluten sensitive
    ask('Are you gluten sensitive? ', foods, ('donuts', 'pancakes', 'waffles', 'bagels'), -1)
    for item, score in foods.items():
        print(item, '=', score)
Now I have a fairly generic function named "ask()" and some code that demonstrates how ask() is used.

I start python, import my module and ask for help.
Output:
>>> import survey >>> help(survey) Help on module survey: NAME survey - survey.py DESCRIPTION Useful functions for writing surveys. FUNCTIONS ask(question, items, yes_items, score=1) Ask quesiton. If input is 'y', add score to each food item in good_foods FILE ...\survey.py
There are also tools that collect all the docstrings from your modules and create nicely formatted user documentation and other kinds of reports.

So to answer you question, the computer does not care what is contained between those triple quotes. That is meant for the user
Reply


Messages In This Thread
RE: getting a syntax error and i don't know why - by deanhystad - May-13-2021, 08:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  World Clock syntax error OscarBoots 1 135 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,280 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 423 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,677 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,267 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,356 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,317 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 929 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,903 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,403 May-18-2022, 06:50 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020