{"id":167,"date":"2020-09-26T12:54:22","date_gmt":"2020-09-26T12:54:22","guid":{"rendered":"https:\/\/dft.wiki\/?p=167"},"modified":"2021-02-07T19:39:36","modified_gmt":"2021-02-07T19:39:36","slug":"working-with-strings","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=167","title":{"rendered":"Working with Strings in Python"},"content":{"rendered":"<p>Follow some examples of how to print information friendly in tab layout:<\/p>\n<pre>last, first = input(\"Enter your last and first names: \").split()\r\nstdID = input(\"Enter your ID: \")\r\nprogram = input(\"Enter your program name: \")\r\nprint(\"\")\r\nprint(\"%-20s\" % \"Programmer name:\", first, last)\r\nprint(\"%-20s\" % \"Programmer ID:\", stdID)\r\nprint(\"%-20s\" % \"Program:\", program)\r\nprint(\"\")\r\nprint(\"Name:\", first.lower(), last.upper())\r\nprint(\"\")\r\nf11, f12 = input(\"Enter the first fruit name and its price: \").split()\r\nf12 = \"$\" + f12\r\nf21, f22 = input(\"Enter the second fruit name and its price: \").split()\r\nf22 = \"$\" + f22\r\nf31, f32 = input(\"Enter the third fruit name and its price: \").split()\r\nf32 = \"$\" + f32\r\nprint(\"\")\r\nprint(\"%-20s %-20s\" % (\"Fruit\",\"Price\/Kg\"))\r\nprint(f11.ljust(20, \" \"), f12.ljust(20, \" \"))\r\nprint(f21.ljust(20, \" \"), f22.ljust(20, \" \"))\r\nprint(f31.ljust(20, \" \"), f32.ljust(20, \" \"))<\/pre>\n<p>Copy, paste, and run this code. See below the output of this program:<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-125\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/09\/image-3-1.png\" alt=\"\" \/><\/figure>\n<p>Another example of how to input data, manipulate data, compute data, and print data:<\/p>\n<pre>fisrt_name, last_name = input(\"Enter your first and last names: \").split()\r\nuser_id = input(\"Enter your ID: \")\r\nprogram_name = input(\"Enter the program name: \")\r\nradius = float(input(\"\\nEnter the radius of the circle: \"))\r\npi = float(3.14159)\r\nprint(\"\\n%-20s\" % \"Programmer name: \" , fisrt_name , last_name)\r\nprint(\"%-20s\" % \"ID: \" , \"%-10s\" % user_id)\r\nprint(\"%-20s\" % \"Program: \" , \"%-10s\" % program_name)\r\nprint(\"\\nA circle of radius\" , radius , \"has:\")\r\nprint(\"%-20s\" % \"1. Circumference: \" , \"%-10.2f\" % (2<em>radius<\/em>pi))\r\nprint(\"%-20s\" % \"2. Area: \" , \"%-10.2f\" % (radius<em>pi<\/em>*2))\r\nprint(\"\\nThe memory location used by r =\" , radius , \"is:\" , id(radius))<\/pre>\n<p>Copy, paste, and run this code to get the same output as shown below:<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-129\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/09\/image-4-1.png\" alt=\"\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Follow some examples of how to print information friendly in tab layout: last, first = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-167","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":7,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":1004,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/1004"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}