{"id":4802,"date":"2022-08-24T14:34:57","date_gmt":"2022-08-24T09:04:57","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/"},"modified":"2022-08-24T14:34:57","modified_gmt":"2022-08-24T09:04:57","slug":"solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/","title":{"rendered":"[Solved] How do you add a list to jump to a line on my code?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-35418505\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"35418505\" data-parentid=\"35413563\" data-score=\"-1\" data-position-on-page=\"2\" data-highest-scored=\"0\" data-question-has-accepted-highest-score=\"0\" itemprop=\"suggestedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>The following code should provide a framework on which to build and extend the program in your question. Most of the code should be fine as it currently written, but you can expand its functionality if needed. To continue building on what questions can be asked and what answers are given, consider adding more sections to the database at the top of the file. The cases are can be easily augmented.<\/p>\n<pre><code>#! \/usr\/bin\/env python3\n\n\"\"\"Cell Phone Self-Diagnoses Program\n\nThe following program is designed to help users to fix problems that they may\nencounter while trying to use their cells phones. It asks questions and tries\nto narrow down what the possible cause of the problem might be. After finding\nthe cause of the problem, a recommended action is provided as an attempt that\ncould possibly fix the user's device.\"\"\"\n\n# This is a database of questions used to diagnose cell phones.\nROOT = 0\nDATABASE = {\n            # The format of the database may take either of two forms:\n            # LABEL: (QUESTION, GOTO IF YES, GOTO IF NO)\n            # LABEL: ANSWER\n            ROOT: ('Does your phone turn on? ', 1, 2),\n            1: ('Does it freeze? ', 11, 12),\n            2: ('Have you plugged in a charger? ', 21, 22),\n            11: ('Did you drop your device in water? ', 111, 112),\n            111: 'Do not charge it and take it to the nearest specialist.',\n            112: 'Try a hard reset when the battery has charge.',\n            12: 'I cannot help you with your phone.',\n            21: 'Charge it with a different charger in a different phone '\n                'socket.',\n            22: ('Plug it in and leave it for 20 minutes. Has it come on? ',\n                 221, 222),\n            221: ('Are there any more problems? ', 222, 2212),\n            222: ('Is the screen cracked? ', 2221, 2222),\n            2212: 'Thank you for using my troubleshooting program!',\n            2221: 'Replace in a shop.',\n            2222: 'Take it to a specialist.'\n            }\n\n# These are possible answers accepted for yes\/no style questions.\nPOSITIVE = tuple(map(str.casefold, ('yes', 'true', '1')))\nNEGATIVE = tuple(map(str.casefold, ('no', 'false', '0')))\n\n\ndef main():\n    \"\"\"Help diagnose the problems with the user's cell phone.\"\"\"\n    verify(DATABASE, ROOT)\n    welcome()\n    ask_questions(DATABASE, ROOT)\n\n\ndef verify(database, root):\n    \"\"\"Check that the database has been formatted correctly.\"\"\"\n    db, nodes, visited = database.copy(), [root], set()\n    while nodes:\n        key = nodes.pop()\n        if key in db:\n            node = db.pop(key)\n            visited.add(key)\n            if isinstance(node, tuple):\n                if len(node) != 3:\n                    raise ValueError('tuple nodes must have three values')\n                query, positive, negative = node\n                if not isinstance(query, str):\n                    raise TypeError('queries must be of type str')\n                if len(query) &lt; 3:\n                    raise ValueError('queries must have 3 or more characters')\n                if not query[0].isupper():\n                    raise ValueError('queries must start with capital letters')\n                if query[-2:] != '? ':\n                    raise ValueError('queries must end with the \"? \" suffix')\n                if not isinstance(positive, int):\n                    raise TypeError('positive node names must be of type int')\n                if not isinstance(negative, int):\n                    raise TypeError('negative node names must be of type int')\n                nodes.extend((positive, negative))\n            elif isinstance(node, str):\n                if len(node) &lt; 2:\n                    raise ValueError('string nodes must have 2 or more values')\n                if not node[0].isupper():\n                    raise ValueError('string nodes must begin with capital')\n                if node[-1] not in {'.', '!'}:\n                    raise ValueError('string nodes must end with \".\" or \"!\"')\n            else:\n                raise TypeError('nodes must either be of type tuple or str')\n        elif key not in visited:\n            raise ValueError('node {!r} does not exist'.format(key))\n    if db:\n        raise ValueError('the following nodes are not reachable: ' +\n                         ', '.join(map(repr, db)))\n\n\ndef welcome():\n    \"\"\"Greet the user of the application using the provided name.\"\"\"\n    print(\"Welcome to Sam's Phone Troubleshooting program!\")\n    name = input('What is your name? ')\n    print('Thank you for using this program, {!s}.'.format(name))\n\n\ndef ask_questions(database, node):\n    \"\"\"Work through the database by asking questions and processing answers.\"\"\"\n    while True:\n        item = database[node]\n        if isinstance(item, str):\n            print(item)\n            break\n        else:\n            query, positive, negative = item\n            node = positive if get_response(query) else negative\n\n\ndef get_response(query):\n    \"\"\"Ask the user yes\/no style questions and return the results.\"\"\"\n    while True:\n        answer = input(query).casefold()\n        if answer:\n            if any(option.startswith(answer) for option in POSITIVE):\n                return True\n            if any(option.startswith(answer) for option in NEGATIVE):\n                return False\n        print('Please provide a positive or negative answer.')\n\n\nif __name__ == '__main__':\n    main()\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">14<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How do you add a list to jump to a line on my code? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] The following code should provide a framework on which to build and extend the program in your question. Most of the code should be fine as it currently written, but you can expand its functionality if needed. To continue building on what questions can be asked and what answers are given, consider adding more &#8230; <a title=\"[Solved] How do you add a list to jump to a line on my code?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/\" aria-label=\"More on [Solved] How do you add a list to jump to a line on my code?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[349,482],"class_list":["post-4802","post","type-post","status-publish","format-standard","hentry","category-solved","tag-python","tag-python-3-x"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] How do you add a list to jump to a line on my code? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How do you add a list to jump to a line on my code? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] The following code should provide a framework on which to build and extend the program in your question. Most of the code should be fine as it currently written, but you can expand its functionality if needed. To continue building on what questions can be asked and what answers are given, consider adding more ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-24T09:04:57+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How do you add a list to jump to a line on my code?\",\"datePublished\":\"2022-08-24T09:04:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/\"},\"wordCount\":103,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"python\",\"python-3.x\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/\",\"name\":\"[Solved] How do you add a list to jump to a line on my code? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-08-24T09:04:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How do you add a list to jump to a line on my code?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How do you add a list to jump to a line on my code? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How do you add a list to jump to a line on my code? - JassWeb","og_description":"[ad_1] The following code should provide a framework on which to build and extend the program in your question. Most of the code should be fine as it currently written, but you can expand its functionality if needed. To continue building on what questions can be asked and what answers are given, consider adding more ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/","og_site_name":"JassWeb","article_published_time":"2022-08-24T09:04:57+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How do you add a list to jump to a line on my code?","datePublished":"2022-08-24T09:04:57+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/"},"wordCount":103,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["python","python-3.x"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/","url":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/","name":"[Solved] How do you add a list to jump to a line on my code? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-08-24T09:04:57+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-do-you-add-a-list-to-jump-to-a-line-on-my-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How do you add a list to jump to a line on my code?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=4802"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4802\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=4802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=4802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=4802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}