[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-572250-105":53,"doc-detail-572250-en":127},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":120,"head_meta":122,"extra_data":124,"updated_unix":126},105,"en","beginners_python_cheat_sheet_pcc_if_while-beginners-python-if-statements-and-while-loops","beginners_python_cheat_sheet_pcc_if_while - Beginner's Python If Statements and While Loops","","Beginner's guide to Python if statements and while loops, explaining how to evaluate conditions with True/False and how programs can respond accordingly. Covers conditional tests including equality, inequality, case-insensitive comparisons via lower(), numerical comparisons, and multi-condition logic using and/or. Includes if, if-else, and if-elif-else patterns, plus list-based membership and empty-list checks. Demonstrates accepting user input with input(), converting with int()/float(), and using while loops with counters, quitting prompts, flags, and break for loop control.",{"@graph":63,"@context":119},[64,80,102],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":51,"@type":70,"position":76},"https://docshare.wps.com/template/general/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/beginners_python_cheat_sheet_pcc_if_while-beginners-python-if-statements-and-while-loops/572250/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/beginners_python_cheat_sheet_pcc_if_while-beginners-python-if-statements-and-while-loops/572250.png","ImageObject",442,249,{"name":88,"@type":89},"awa","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-24","2026-10-13",true,{"@type":98,"interactionType":99,"userInteractionCount":101},"InteractionCounter",{"@type":100},"ViewAction",6,{"@type":103,"mainEntity":104},"FAQPage",[105,111,115],{"name":106,"@type":107,"acceptedAnswer":108},"How do Python if statements decide whether code runs?","Question",{"text":109,"@type":110},"Python if statements evaluate conditional tests that result in True or False, and execute the associated block only when the result is True.","Answer",{"name":112,"@type":107,"acceptedAnswer":113},"What is the difference between a single equal sign and a double equal sign in conditional tests?",{"text":114,"@type":110},"A single equal sign assigns a value to a variable, while a double equal sign checks whether two values are equal.",{"name":116,"@type":107,"acceptedAnswer":117},"How can a while loop run until the user chooses to quit?",{"text":118,"@type":110},"Use a loop that continues while an entered message is not 'quit', updating the message each iteration with input() and printing it only when it isn’t 'quit'.","https://schema.org",{"og:url":78,"og:type":121,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":123,"canonical":78},"index,follow",{"doc_id":125,"site_id":56},572250,1792112378,{"code":4,"msg":5,"data":128},{"doc_id":125,"user_id":129,"nickname":88,"user_avatar":130,"doc_module":9,"category_id":50,"category_name":51,"doc_title":59,"doc_description":61,"doc_content":131,"file_id":132,"file_url":133,"file_type":134,"file_size":135,"view_count":101,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":73,"language":136,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":137,"faqs":138,"seo_title":139,"seo_description":61,"update_tm":140,"read_time":9},3985747858093,"https://ap-avatar.wpscdn.com/davatar_3d24733baf745e90a7e4bdd5f77d97b2","Beginner's Python Cheat SheetIf Statementsand While Loops  \nWhat are if statements? What are while loops?  \nPython's if statements allow you to examine the current state of a program and respond appropriately to that state. You can write a simple if statement that checks one condition, or you can create a complex series of statements that identify the exact conditions you're interested in.  \nwhile loops run as long as certain conditions remain true. You can use while loops to let your programs run as long as your users want them to.  \nConditional Tests  \nA conditional test is an expression that can be evaluated as true or false. Python uses the values True and False to decide whether the code in an if statement should be executed.  \nChecking for equality  \nA single equal sign assigns a value to a variable. A double equal sign checks whether two values are equal.  \nIf your conditional tests aren't doing what you expect them to, make sure you're not accidentally using a single equal sign.  \n>>> car = 'bmw'  \n>>> car == 'bmw'True  \n>>> car = 'audi'  \n>>> car == 'bmw'False  \nIgnoring case when making a comparison >>> car = 'Audi'  \n>>> car.lower() == 'audi'True  \nChecking for inequality >>> topping = 'mushrooms'>>> topping != 'anchovies'True  \nNumerical comparisons  \nTesting numerical values is similar to testing string values.  \nTesting equality and inequality >>> age = 18  \n>>> age == 18 True >>> age != 18  \nFalse  \nComparison operators >>> age = 19  \n>>> age \u003C 21 True >>> age \u003C= 21 True >>> age > 21 False >>> age >= 21 False  \nChecking multiple conditions  \nYou can check multiple conditions at the same time. The and operator returns True if all the conditions listed are true. The or operator returns True if any condition is true.  \nUsing and to check multiple conditions >>> age_0 = 22  \n>>> age_1 = 18  \n>>> age_0 >= 21 and age_1 >= 21 False  \n>>> age_1 = 23  \n>>> age_0 >= 21 and age_1 >= 21 True  \nUsing or to check multiple conditions >>> age_0 = 22  \n>>> age_1 = 18  \n>>> age_0 >= 21 or age_1 >= 21 True  \n>>> age_0 = 18  \n>>> age_0 >= 21 or age_1 >= 21 False  \nBoolean values  \nA boolean value is either True or False. Variables with boolean values are often used to keep track of certain conditions within a program.  \nSimple boolean values game_active = True is_valid = True can_edit = False  \nIf statements  \nSeveral kinds of if statements exist. Your choice of which to use depends on the number of conditions you need to test. You can have as many elif blocks as you need, and the else block is always optional.  \nSimple if statement age = 19  \nif age >= 18:  \nprint(\"You're old enough to vote!\") If-else statements  \nage = 17  \nif age >= 18:  \nprint(\"You're old enough to vote!\") else:  \nprint(\"You can't vote yet.\")  \nThe if-elif-else chain age = 12  \nif age \u003C 4: price = 0  \nelif age \u003C 18: price = 25  \nelse:  \nprice = 40  \nprint(f\"Your cost is ${price}.\")  \nConditional tests with lists  \nYou can easily test whether a certain value is in a list. You can also test whether a list is empty before trying to loop through the list.  \nTesting if a value is in a list  \n>>> players = ['al', 'bea', 'cyn', 'dale']>>> 'al' in players  \nTrue  \n>>> 'eric' in players False  \nTesting if two values are in a list  \n>>> 'al' in players and 'cyn' in players  \nPython Crash Course A Hands-on, Project-Based Introduction to Programming  \n[ehmatthes.github.io/pcc_3e](ehmatthes.github.io/pcc_3e)  \nConditional tests with lists (cont. )  \nTesting if a value is not in a list banned_users = ['ann', 'chad', 'dee'] user = 'erin'  \nif user not in banned_users: print(\"You can play!\")  \nChecking if a list is empty  \nAn empty list evaluates as False in an if statement. players = []  \nif players:  \nfor player in players:  \nprint(f\"Player: {player.title()}\") else:  \nprint(\"We have no players yet!\")  \nAccepting input  \nYou can allow your users to enter input using the input() function. All input is initially stored as a string. If you want to accept numerical input, you'll ","cbCaibHoE7BhOSnR","https://ap.wps.com/l/cbCaibHoE7BhOSnR","pdf",278793,"English","# Beginner's Python If Statements and While Loops\n## What are if statements?\n## What are while loops?\n## Conditional Tests\n## If statements and branches\n## Conditional tests with lists\n## Accepting input\n## While loops and loop control","[{\"question\":\"How do Python if statements decide whether code runs?\",\"answer\":\"Python if statements evaluate conditional tests that result in True or False, and execute the associated block only when the result is True.\"},{\"question\":\"What is the difference between a single equal sign and a double equal sign in conditional tests?\",\"answer\":\"A single equal sign assigns a value to a variable, while a double equal sign checks whether two values are equal.\"},{\"question\":\"How can a while loop run until the user chooses to quit?\",\"answer\":\"Use a loop that continues while an entered message is not 'quit', updating the message each iteration with input() and printing it only when it isn’t 'quit'.\"}]","beginners_python_cheat_sheet_pcc_if_while - Beginner's Python If Statements and While Loops | PDF",1791926354]