{"id":26172302,"url":"https://github.com/imdarshangk/loops-python","last_synced_at":"2025-03-11T19:55:59.466Z","repository":{"id":156251801,"uuid":"594122671","full_name":"imDarshanGK/Loops-python","owner":"imDarshanGK","description":"It is used to execute a statement or Group of statement for multiple time.","archived":false,"fork":false,"pushed_at":"2024-04-22T02:47:33.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-22T04:57:45.868Z","etag":null,"topics":["forloops","whileloops"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imDarshanGK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-01-27T16:47:57.000Z","updated_at":"2024-04-23T12:57:44.438Z","dependencies_parsed_at":"2024-04-23T12:57:40.239Z","dependency_job_id":null,"html_url":"https://github.com/imDarshanGK/Loops-python","commit_stats":null,"previous_names":["imdarshangk/loops-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imDarshanGK%2FLoops-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imDarshanGK%2FLoops-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imDarshanGK%2FLoops-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imDarshanGK%2FLoops-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imDarshanGK","download_url":"https://codeload.github.com/imDarshanGK/Loops-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243104175,"owners_count":20236943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["forloops","whileloops"],"created_at":"2025-03-11T19:55:58.817Z","updated_at":"2025-03-11T19:55:59.456Z","avatar_url":"https://github.com/imDarshanGK.png","language":"Python","readme":"# Loops Python\n\n## Overview\nThis repository is dedicated to understanding and practicing **loops** in Python. It includes programs and exercises demonstrating the usage of `for` and `while` loops. The repository is suitable for beginners looking to grasp Python's iterative constructs effectively.\n\n## Features\n- Comprehensive examples of `for` and `while` loops.\n- Practical exercises covering common use cases of loops.\n- Clear and well-documented Python code for learning and reference.\n\n## Contents\n- **For Loops**: Iterating over sequences, ranges, and collections.\n- **While Loops**: Looping with conditions and control mechanisms.\n\n##  Loops\n```\nSyntax:\nwhile(condition):\n    #statement\n```\n\n##  Forloop remove unit digit\nProgram to remove unit digit in a number\n\nExample 1:\n```\nEnter a number: 4596 \nNumber after removing unit digit= 459\n```\n\n## Forloop find unit digit\nProgram to find unit digit in a number.\n\nunits digit of a number is the digit in the one's place of the number. It is the rightmost digit of the number.\n\nExample 1:\n```\nEnter a number: 545\nUnit digit in a number 5\n ```   \n\n## Whileloop count number\nwhile loop count numbers\n```\ncondition : Run loop till count is less than 10\n\n    1\n    2\n    3\n    4\n    5\n    6\n    7\n    8\n    9\n```\n\n## Sum of unit digit\nforloop\n\nProgram to find sum of unit digit in a given number.\n```\nProgram Explanation:\n1. User must first enter the value and store it in a variable.\n2. The for loop is used and the last digit of the number is obtained by using the modulus operator.\n3. The digit is added to another variable each time the loop is executed.\n4. This loop terminates when the value of the number is 0.\n5. The total sum of the number is then printed.\n```\n```\nExample 1:\n\n    Enter a number: 1235\n    Sum= 11\n\nExample 2:\n\n    Enter a number: 2598\n    Sum= 24\n\nExample 3:\n\n    Enter a number: 9875325\n    Sum= 39\n```\n    \n## Sum of digits\nwhile loop\n```\nProgram Explanation:\n1} User must first enter the value and store it in a variable.\n2} The for loop is used and the last digit of the number is obtained by using the modulus operator.\n3} The digit is added to another variable each time the loop is executed.\n4} This loop terminates when the value of the number is 0.\n5} The total sum of the number is then printed.\n\nExample 1:\n\n    Enter a number \u003e\u003e 55\n    Sum of digits = 10\n    \nExample 2:\n\n    Enter a number \u003e\u003e 365\n    Sum of digits = 14\n```\n\n## Reverse of digits\nReverse of digits\n```\nProgram Explanation:\n\n1} User must first enter the value and store it in a variable n.\n2} The for loop is used and the last digit of the number is obtained by using the modulus operator.\n3} The last digit is then stored at the one’s place, second last at the ten’s place and so on.\n4} The last digit is then removed by truly dividing the number with 10.\n5} This loop terminates when the value of the number is 0.\n6} The reverse of the number is then printed.\n\nExample 1:\n\n    Enter a number: 548\n    Reverse of digits= 845\n\nExample 2:\n\n    Enter a number: 987\n    Reverse of digits= 789\n\nExample 3:\n    \n    Enter a number: 739\n    Reverse of digits= 937\n```\n    \n## Product of digits\nProduct of digits\n```\nExample 1:\n\n    Enter a number: 4586\n    Product of digits= 960\n\nExample 2:\n\n    Enter a number: 325\n    Product of digits= 30\n\nExample 3:\n\n    Enter a number: 39\n    Product of digits= 27\n```        \n    \n## Armstrong number\nArmstrong number\n```\nProgram Explanation \u003e\u003e\n\n1} User must enter the number and store it in a variable.\n2} The map function obtains each digit from the number and converts it to a string and stores it in a list.\n3} The second map function cubes each digit and stores it in another list.\n4} Then the sum of the cubes of the digits is found and is checked if it is equal to the original number.\n5} If the sum of the cube of digits is equal to the original number, the number is an Armstrong number.\n6} The final result is printed.\n\nExample 1:\n\n    Enter a number: 153\n    Sum= 153\n    It is a Armstrong number\n\nExample 2:\n\n    Enter a number: 125\n    Sum= 134\n    It is not a Armstrong number\n\nExample 3:\n\n    Enter a number: 407\n    Sum= 407\n    It is a Armstrong number\n\nExample 4:\n\n    Enter a number: 469\n    Sum= 1009\n    It is not a Armstrong number\n ```     \n## Range\nrange\n```\nSyntax:\nfor i in range(start,end):\n   //statement\n```\n```           \nProgram Explanation:\n\n      * Start value included\n      * end value.(Excluded)\n      * I value gets auto incremented by 1 (Default)\n      \nExample:\n\n    0 Python\n    1 Python\n    2 Python\n    3 Python\n    4 Python\n    5 Python\n```\n\n## 𝐏𝐚𝐥𝐢𝐧𝐝𝐫𝐨𝐦𝐞 𝐧𝐮𝐦𝐛𝐞𝐫\n𝐏𝐚𝐥𝐢𝐧𝐝𝐫𝐨𝐦𝐞 𝐧𝐮𝐦𝐛𝐞𝐫\n\n𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐃𝐞𝐬𝐜𝐫𝐢𝐩𝐭𝐢𝐨𝐧:\n```\nThe program takes a number and checks whether it is a palindrome or not.\n```\n```\nProgram Explanation:\n    \n1} User must first enter the value of the integer and store it in a variable.\n2} The value of the integer is then stored in another temporary variable.\n3} The for loop is used and the last digit of the number is obtained by using the modulus operator.\n4} The last digit is then stored at the one’s place, second last at the ten’s place and so on.\n5} The last digit is then removed by truly dividing the number with 10.\n6} This loop terminates when the value of the number is 0.\n7} The reverse of the number is then compared with the integer value stored in the temporary variable.\n8} If both are equal, the number is a palindrome.\n9} If both aren’t equal, the number isn’t a palindrome.\n10} The final result is then printed.\n\nExample 1:\n    \n    Enter a number: 121\n    reverse= 121\n    it is a Palindrome number\n\nExample 2:\n\n    Enter a number: 984\n    reverse= 489\n    it is not a Palindrome number\n\nExample 3:\n\n    Enter a number: 737\n    reverse= 737\n    it is a Palindrome number\n\nExample 4:\n    \n    Enter a number: 845\n    reverse= 548\n    it is not a Palindrome number\n```\n\n## Sum of cubes\nSum of cubes\n```\nExample 1:\n\n    Enter a number: 12\n    Sum of cubes= 6084\n\nExample 2:\n\n    Enter a number: 3\n    Sum of cubes= 36\n\nExample 3:\n\n    Enter a number: 5\n    Sum of cubes= 225\n```\n\n## Factorial\nFactorial\n```\nProgram Explanation:\n\n    * User must enter a number.\n    * A factorial variable is initialized to 1.\n    * A for loop is used to multiply the number to the factorial variable and then the number is decremented each time.\n    * This continues till the value of n+1.\n    * The factorial of the number is printed.\n\nExample 1:\n\n    Enter a number: 5\n    Factorial= 120\n\nExample 2:\n\n    Enter a number: 3\n    Factorial= 6\n\nExample 3:\n\n    Enter a number: 10\n    Factorial= 3628800\n```\n\n## Number of factors\nNumber of factors\n```\nExample 1:\n\n    Enter a number: 22\n    factors are\n    1\n    2\n    11\n    22\n    Number of factors= 4\n\nExample 2:\n\n    Enter a number: 5\n    factors are\n    1\n    5\n    Number of factors= 2\n\nExample 3:\n\n    Enter a number: 8\n    factors are\n    1\n    2\n    4\n    8\n    Number of factors= 4\n\nExample 4:\n\n    Enter a number: 20\n    factors are\n    1\n    2\n    4\n    5\n    10\n    20\n    Number of factors= 6\n```\n\n## Prime number and Not a prime number\nPrime number and Not a prime number \n```\nProgram Explanation:\n\n* User must enter the number to be checked and store it in a different variable.\n* The count variable is first initialized to 0.\n* The for loop ranges from 1 of the number.\n* The if statement then checks for the modules of the number if the remainder is equal to 0.\n* The count variable counts the number of modules and if the count is equal to 2, the number is a prime number.\n* If the count is not equal 2, the number is n’t a prime number.\n* The final result is printed.\n\nExample 1:\n\n    Enter a number: 12\n    factors are\n    1\n    2\n    3\n    4\n    6\n    12\n    Number of factors= 6\n    Not a Prime number\n\nExample 2:\n    \n    Enter a number: 11\n    factors are\n    1\n    11\n    Number of factors= 2\n    Prime number\n\nExample 3:\n\n    Enter a number: 22\n    factors are\n    1\n    2\n    11\n    22\n    Number of factors= 4\n    Not a Prime number\n\nExample 4:\n\n    Enter a number: 31\n    factors are\n    1\n    31\n    Number of factors= 2\n    Prime number\n```\n\n## Sum of factors\nSum of factors\n```\nExample 1:\n\n    Enter a number: 28\n    Sum of factors= 28\n    Perfect number\n\n\nExample 2:\n\n    Enter a number: 25\n    Sum of factors= 6\n    Not a Perfect number\n\n\nExample 3:\n    \n    Enter a number: 6\n    Sum of factors= 6\n    Perfect number\n\n\nExample 4:\n\n    Enter a number: 8\n    Sum of factors= 7\n    Not a Perfect number\n```\n\n## Factors\nFactors are\n```\nExample 1:\n\n    Enter a number: 12\n    Factors are \n    1\n    2\n    3\n    4\n    6\n    12\n\nExample 2:\n\n    Enter a number: 11\n    Factors are\n    1\n    11\n\nExample 3:\n\n    Enter a number: 6\n    Factors are\n    1\n    2\n    3\n    6\n\nExample 4:\n\n    Enter a number: 31\n    Factors are\n    1\n    31\n```\n\n## factorial of n integer\nfactorial of n integer\n\nProblem Description:\n```\nThe program takes a number and finds the factorial of that number without using recursion.\n  ```\n```  \nProgram Explanation:\n    \n1} User must enter a number.\n2} A factorial variable is initialized to 1.    \n3} A for loop is used to multiply the number to the factorial variable and then the number is decremented each time.    \n4} This continues till the value of the number is greater than 0.    \n5} The factorial of the number is printed.\n\nExample 1:\n\n    Enter a number: 10\n    Factorial of integer is 3628800\n\nExample 2:\n\n    Enter a number: 8\n    Factorial of integer is 40320\n\nExample 3:\n\n    Enter a number: 9\n    Factorial of integer is 362880\n\nExample 4:\n\n    Enter a number: 25\n    Factorial of integer is 15511210043330985984000000\n```\n    \n## Number Sum Calculator\nNumber sum calculator\n```\nEnter a number(0 to quit)\u003e\u003e 2\nEnter a number(0 to quit)\u003e\u003e -5\nEnter a number(0 to quit)\u003e\u003e 5\nEnter a number(0 to quit)\u003e\u003e 10\nEnter a number(0 to quit)\u003e\u003e -4\nEnter a number(0 to quit)\u003e\u003e 0\nTotal is 8\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimdarshangk%2Floops-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimdarshangk%2Floops-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimdarshangk%2Floops-python/lists"}