{"id":4184,"date":"2024-08-19T05:59:55","date_gmt":"2024-08-19T05:59:55","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=4184"},"modified":"2024-08-19T06:35:54","modified_gmt":"2024-08-19T06:35:54","slug":"how-to-ask-user-input-in-python-until-valid-response","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/","title":{"rendered":"How to Ask User Input in Python Until Valid Response"},"content":{"rendered":"\n<p>These days Python applications need to be interactive and give results based on user input. So Python developers need to be able to ask user input from within Python script or application. Accepting user input is one thing and accepting a valid user input is a different thing altogether. This is because, when you ask for user input, if they enter improper values then your Python script\/application will crash and not proceed further. Therefore, we need also add a little bit of input validation and error handling to solve this problem. In this article, we will learn how to ask user input in Python until valid response.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#Accepting_User_Input_in_Python\" >Accepting User Input in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#How_to_Ask_User_Input_in_Python_Until_Valid_Response\" >How to Ask User Input in Python Until Valid Response<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#1_Accept_User_Input\" >1. Accept User Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#2_Add_Input_Validation\" >2. Add Input Validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#3_Create_Function\" >3. Create Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Accepting_User_Input_in_Python\"><\/span>Accepting User Input in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>It is very easy to accept user input Python, using input() function. Here is an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">age = int(input(\"Enter your age:\"))<\/pre>\n\n\n\n<p>When you run the following command or script with this command, you will see the following output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter your age:<\/pre>\n\n\n\n<p>If you enter values like 20, 30, etc. the above code will work properly. If you enter text values twenty, thirty, etc. it will throw the following error.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Traceback (most recent call last):<br>  File \"&lt;stdin&gt;\", line 1, in &lt;module&gt;<br>  File \"&lt;string&gt;\", line 1, in &lt;module&gt;<br>NameError: name 'twenty' is not defined<\/pre>\n\n\n\n<p>This is because Python expects a numerical value whereas we have provided a string input. That is why we need to include some kind of validation to make sure users do not enter improper values, and also put the input() function inside some kind of a loop so that in case the user inputs erroneous values, the program asks the users to enter input again. Finally, we also need to add exception handling to catch any unforeseen issues. We will look at how to do this in this article.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Ask_User_Input_in_Python_Until_Valid_Response\"><\/span>How to Ask User Input in Python Until Valid Response<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the steps to build a code that asks for user input until it gets a valid response.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Accept_User_Input\"><\/span>1. Accept User Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here is a simple code to keep asking for user input until they enter proper values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">while True:<br>    try:<br>        age = int(input(\"Please enter your age: \"))<br>    except ValueError:<br>        print(\"Please enter numeric value\")<br>        continue<\/pre>\n\n\n\n<p>In the above code, we call input() function inside try&#8230;except block to catch any errors thrown due to invalid inputs. Since we need to ask user input till we get valid input, we add this try&#8230;except block in a while loop. The try-except block will make sure that in case users do not enter numerical values, the program does not throw an exception. The while loop makes sure that the program asks user input once again.<\/p>\n\n\n\n<p>We have used ValueError exception type. If you do not know what it does, or want to catch a broader set of exceptions, then simply use <a href=\"https:\/\/docs.python.org\/3\/tutorial\/errors.html\" target=\"_blank\" rel=\"noreferrer noopener\">Exception<\/a> keyword instead.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">while True:<br>    try:<br>        age = int(input(\"Please enter your age: \"))<br>    except <strong>Exception as e<\/strong>:<br>        print(\"Please enter numeric value\")<br>        continue<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Add_Input_Validation\"><\/span>2. Add Input Validation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can add custom input validation such as the checking if the value is negative, to the above code. Make sure to add it inside the while loop, after try-except block. This is because you need to run all the input validation for each user input.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">while True: <br>    try:<br>      ...<br>    except:<br>      ...<br><br><br>    if age &lt; 0:<br>        print(\"Please enter number > 0\")<br>        continue<br>    else:        <br>        break<br>   ...<\/pre>\n\n\n\n<p>After the while loop we will add an if block that checks if the age is greater than 20 or not and give final output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if age &gt;= 20: \n    print(\"You are eligible\")\nelse:\n    print(\"You are not eligible\")<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Create_Function\"><\/span>3. Create Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>It is convenient to put the above code in a function so that you can call it whenever you want. Here is the complete code to do it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def get_age(age):<br>    while True:<br>        try:<br>            age = int(input(\"Please enter your age: \"))<br>        except Exception as e:<br>            print(\"Please enter numeric value\")<br>            continue<br><br>        if age &lt; 0:<br>            print(\"Please enter number &gt; 0\")<br>            continue<br>        else:        <br>            break<br><br>    if age &gt;= 20: <br>        print(\"You are eligible\")<br>    else:<br>        print(\"You are not eligible\")<\/pre>\n\n\n\n<p>You can call the above function as shown.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">age = get_age(\"Please enter age:\")<\/pre>\n\n\n\n<p>Of course, you can also include these validations in another function and call it, to simplify your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt how to ask user input in Python until valid values are received. The key is to call input() function inside a try&#8230;except block, which in turn is present in a loop. In each iteration of your loop, you can add custom validations to check if the value is as per your expectation. It is very important to add exception handling as well as input validation to make sure that invalid inputs are handled and your loop does not terminate unexpectedly.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-bind-events-to-dynamically-created-elements-in-javascript\/\">How to Dynamically Bind Events in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-password-protect-directory-in-nginx\/\">How to Password Protect Directory in NGINX<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/apache-deny-access-to-url-files-directory\/\">Apache Deny Access to URL, Files &amp; Directory<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/nginx-restrict-access-to-directory-and-subdirectories\/\">NGINX Restrict Access to Directory &amp; Subdirectories<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often Python developers need to ask for user input to process further. Here is how to ask user input in Python Until valid response.<\/p>\n","protected":false},"author":1,"featured_media":4208,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[302],"class_list":["post-4184","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-user-input"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Ask User Input in Python Until Valid Response - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often Python developers need to ask for user input to process further. Here is how to ask user input in Python Until valid response.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Ask User Input in Python Until Valid Response - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often Python developers need to ask for user input to process further. Here is how to ask user input in Python Until valid response.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2024-08-19T05:59:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-19T06:35:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/08\/ask-user-input-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"503\" \/>\n\t<meta property=\"og:image:height\" content=\"378\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\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:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Ask User Input in Python Until Valid Response\",\"datePublished\":\"2024-08-19T05:59:55+00:00\",\"dateModified\":\"2024-08-19T06:35:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/\"},\"wordCount\":674,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/ask-user-input-python.jpg?fit=503%2C378&ssl=1\",\"keywords\":[\"user input\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/\",\"name\":\"How to Ask User Input in Python Until Valid Response - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/ask-user-input-python.jpg?fit=503%2C378&ssl=1\",\"datePublished\":\"2024-08-19T05:59:55+00:00\",\"dateModified\":\"2024-08-19T06:35:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often Python developers need to ask for user input to process further. Here is how to ask user input in Python Until valid response.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/ask-user-input-python.jpg?fit=503%2C378&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/ask-user-input-python.jpg?fit=503%2C378&ssl=1\",\"width\":503,\"height\":378,\"caption\":\"ask user input in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-ask-user-input-in-python-until-valid-response\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Ask User Input in Python Until Valid Response\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Ask User Input in Python Until Valid Response - Ubiq BI","description":"Often Python developers need to ask for user input to process further. Here is how to ask user input in Python Until valid response.","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:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/","og_locale":"en_US","og_type":"article","og_title":"How to Ask User Input in Python Until Valid Response - Ubiq BI","og_description":"Often Python developers need to ask for user input to process further. Here is how to ask user input in Python Until valid response.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2024-08-19T05:59:55+00:00","article_modified_time":"2024-08-19T06:35:54+00:00","og_image":[{"width":503,"height":378,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/08\/ask-user-input-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Ask User Input in Python Until Valid Response","datePublished":"2024-08-19T05:59:55+00:00","dateModified":"2024-08-19T06:35:54+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/"},"wordCount":674,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/08\/ask-user-input-python.jpg?fit=503%2C378&ssl=1","keywords":["user input"],"articleSection":["Python"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/","name":"How to Ask User Input in Python Until Valid Response - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/08\/ask-user-input-python.jpg?fit=503%2C378&ssl=1","datePublished":"2024-08-19T05:59:55+00:00","dateModified":"2024-08-19T06:35:54+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often Python developers need to ask for user input to process further. Here is how to ask user input in Python Until valid response.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/08\/ask-user-input-python.jpg?fit=503%2C378&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/08\/ask-user-input-python.jpg?fit=503%2C378&ssl=1","width":503,"height":378,"caption":"ask user input in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-ask-user-input-in-python-until-valid-response\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Ask User Input in Python Until Valid Response"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/08\/ask-user-input-python.jpg?fit=503%2C378&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-15u","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=4184"}],"version-history":[{"count":28,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4184\/revisions"}],"predecessor-version":[{"id":4217,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4184\/revisions\/4217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/4208"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=4184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=4184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=4184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}