{"id":6813,"date":"2022-09-05T06:54:59","date_gmt":"2022-09-05T01:24:59","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/"},"modified":"2022-09-05T06:54:59","modified_gmt":"2022-09-05T01:24:59","slug":"solved-im-very-new-to-programming-is-this-acceptable-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/","title":{"rendered":"[Solved] I&#8217;m very new to programming. Is this acceptable? [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-23164785\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"23164785\" data-parentid=\"23164478\" data-score=\"1\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" 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>It seems you have two unrelated questions here.<\/p>\n<p>The first is whether your <code>calculateTutitionIncrease<\/code> function does the right thing to create an list of cost values over time.<\/p>\n<p>It is not bad, exactly, but it could be better. To start with, you could use a <code>for<\/code> loop over a <code>range<\/code>, rather than a <code>while<\/code> loop testing an integer that you manually increment. An even more &#8220;Pythonic&#8221; style of code is to use a list comprehension when you want to create a list of items from some other sequence (like the range of year numbers). This requires a slightly different mathematical calculation in this case, but the results should be the same:<\/p>\n<pre><code>costs_per_year = [cost * (1+increase)**year for year in range(1, years+1)]\n<\/code><\/pre>\n<p>Your second question seems to be about whether you should keep your code for asking if the user wants to quit in a separate function. This is fairly subjective, so there really isn&#8217;t a single right answer. I think there are two good reasons that you might want to have it in its own function.<\/p>\n<p>First, it can help make your other code simpler, especially if most of the other work is also separated out into functions:<\/p>\n<pre><code>def main():\n    while True:\n        input_data = get_input()\n        results = calculate_results(input_data)\n        display_results(results)\n        if ask_to_exit():\n            break\n<\/code><\/pre>\n<p>You don&#8217;t see much benefit to this currently, because your <code>main<\/code> function is already quite long and complicated.<\/p>\n<p>The second reason is if you might want to call it from multiple different places in your other code. For instance, if you had two different loops, it might make sense to use the same function to ask the user if they were done in each of them. This doesn&#8217;t currently apply to your code though, since you only call your <code>exitProgram<\/code> function in exactly one place.<\/p>\n<p>So, in the end, neither of the reasons speak strongly to your situation. That doesn&#8217;t necessarily mean that you should stick the contents of <code>exitProgram<\/code> back into <code>main<\/code> though. If you think you might change the other code (for instance, by factoring out the other steps you go through in <code>main<\/code> into functions of their own), it might make sense to keep <code>exitProgram<\/code> as a separate function too.<\/p>\n<p>A few further suggestions:<\/p>\n<p>Pick a different name for your <code>exitProgram<\/code> function, if you choose to keep it. Functions are usually given names that are verbs describing what they do. Your <code>exitProgram<\/code> function is misleading though, since it doesn&#8217;t actually cause the program to exit (it just returns what the users desire is, regarding exiting). I&#8217;d suggest that you make it return a <code>bool<\/code> value too, rather than a <code>y<\/code> or <code>n<\/code> string that the caller will need to test against.<\/p>\n<p>Also, Python code convention is for functions and variables to be named in <code>lower_case_with_underscores<\/code> format, rather than <code>camelCase<\/code> like you are currently using. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0008\">See PEP 8<\/a> for more Python style suggestions.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">2<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved I&#8217;m very new to programming. Is this acceptable? [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] It seems you have two unrelated questions here. The first is whether your calculateTutitionIncrease function does the right thing to create an list of cost values over time. It is not bad, exactly, but it could be better. To start with, you could use a for loop over a range, rather than a while &#8230; <a title=\"[Solved] I&#8217;m very new to programming. Is this acceptable? [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/\" aria-label=\"More on [Solved] I&#8217;m very new to programming. Is this acceptable? [closed]\">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":[413,349],"class_list":["post-6813","post","type-post","status-publish","format-standard","hentry","category-solved","tag-function","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] I&#039;m very new to programming. Is this acceptable? [closed] - 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-im-very-new-to-programming-is-this-acceptable-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] I&#039;m very new to programming. Is this acceptable? [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] It seems you have two unrelated questions here. The first is whether your calculateTutitionIncrease function does the right thing to create an list of cost values over time. It is not bad, exactly, but it could be better. To start with, you could use a for loop over a range, rather than a while ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-05T01:24:59+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] I&#8217;m very new to programming. Is this acceptable? [closed]\",\"datePublished\":\"2022-09-05T01:24:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/\"},\"wordCount\":465,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"function\",\"python\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/\",\"name\":\"[Solved] I'm very new to programming. Is this acceptable? [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-05T01:24:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] I&#8217;m very new to programming. Is this acceptable? [closed]\"}]},{\"@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\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] I'm very new to programming. Is this acceptable? [closed] - 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-im-very-new-to-programming-is-this-acceptable-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] I'm very new to programming. Is this acceptable? [closed] - JassWeb","og_description":"[ad_1] It seems you have two unrelated questions here. The first is whether your calculateTutitionIncrease function does the right thing to create an list of cost values over time. It is not bad, exactly, but it could be better. To start with, you could use a for loop over a range, rather than a while ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/","og_site_name":"JassWeb","article_published_time":"2022-09-05T01:24:59+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] I&#8217;m very new to programming. Is this acceptable? [closed]","datePublished":"2022-09-05T01:24:59+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/"},"wordCount":465,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["function","python"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/","name":"[Solved] I'm very new to programming. Is this acceptable? [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-05T01:24:59+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-im-very-new-to-programming-is-this-acceptable-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] I&#8217;m very new to programming. Is this acceptable? [closed]"}]},{"@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\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","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\/6813","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=6813"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6813\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=6813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=6813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=6813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}