filmov
tv
Loops In Python โ Part 1 (While Loop) | Class 6 of 10 | Python Foundation Course

ะะพะบะฐะทะฐัั ะพะฟะธัะฐะฝะธะต
๐๐ฑ๐๐ซ๐๐ข๐ฌ๐๐ฌ ๐๐ซ๐ ๐ ๐ข๐ฏ๐๐ง ๐๐๐ฅ๐จ๐ฐ.
This is part of a series on Python Foundation Course for beginners. In this class, we will learn about the an important loop statement in Python, called While Loop. We will learn about two different versions or two different styles of the loop - one with a loop condition, and another is an infinite loop with a suitable Break statetment.
๐๐จ๐ฎ ๐๐๐ง ๐ญ๐ซ๐ฒ ๐ญ๐ก๐ ๐๐จ๐ฅ๐ฅ๐จ๐ฐ๐ข๐ง๐ ๐๐ฑ๐๐ซ๐๐ข๐ฌ๐๐ฌ ๐๐จ๐ซ ๐ฉ๐ซ๐๐๐ญ๐ข๐๐:
1. Ask the user to enter a number. Calculate the number of digits in this number. (Hint: Divide the number by 10, Get the digit in the unit place, Subtract from the original number, Repeat this process inside a While Loop until the number becomes zero. This hint is just a high level direction, you need to think through and implement the details correctly).
2. Ask the user to enter a number. Get each digit in this number and add them into a list. Now, reverse this list, create the reverse number and print the number backward. Example: User enters 123456, program output will be 654321.
3. Do the above exercise without using a list. Just keep building the reverse number step by step in the same loop where you extract the digits from the original number. And finally display the number you built. (There are smarter ways to do this, but try to do it as directed here, so that you learn the use of While Loop better, ultimately that is our aim).
4. Ask the user to enter a number. Check if it is an even number or odd number. If it is an even number, display all the even numbers starting with zero, up to the number entered by the user. And if the user entered an odd number, display all the odd numbers starting with one, up to the number entered by the user.
5. Ask the user to enter a number. Calculate the sum of the digits in this number. Then use this result as the new number and again calculate the sum of the digits in it. Loop through this process until you end up with a single digit number. This is called the Digit-Sum of the original number. Display the Digit-Sum of the number entered by the user. Example: User enters 456789, program output will be 3. (Hint: You will need to use a nested While Loop here, i.e. a While Loop within another While Loop. The outer loop will repeat the entire process, and the inner loop will extract the digits in a number. You can do it using a single While Loop also, but that will become very complex and untidy.)
๐๐ฒ๐ญ๐ก๐จ๐ง ๐ ๐จ๐ฎ๐ง๐๐๐ญ๐ข๐จ๐ง ๐๐จ๐ฎ๐ซ๐ฌ๐ ๐๐ฎ๐ญ๐จ๐ซ๐ข๐๐ฅ๐ฌ
If you are new to Python or new to programming, you can watch the following tutorials to make a solid foundation in Python. Above all tutorials, remember that practice makes a man perfect. So the more you spend time in writing Python programs, the more knowledge and efficiency you will achieve. I wish you all the best with this programming software and a successful coding experience.
If you have any question on this tutorial, please leave your comment below.
#Python #Programming #Coding
This is part of a series on Python Foundation Course for beginners. In this class, we will learn about the an important loop statement in Python, called While Loop. We will learn about two different versions or two different styles of the loop - one with a loop condition, and another is an infinite loop with a suitable Break statetment.
๐๐จ๐ฎ ๐๐๐ง ๐ญ๐ซ๐ฒ ๐ญ๐ก๐ ๐๐จ๐ฅ๐ฅ๐จ๐ฐ๐ข๐ง๐ ๐๐ฑ๐๐ซ๐๐ข๐ฌ๐๐ฌ ๐๐จ๐ซ ๐ฉ๐ซ๐๐๐ญ๐ข๐๐:
1. Ask the user to enter a number. Calculate the number of digits in this number. (Hint: Divide the number by 10, Get the digit in the unit place, Subtract from the original number, Repeat this process inside a While Loop until the number becomes zero. This hint is just a high level direction, you need to think through and implement the details correctly).
2. Ask the user to enter a number. Get each digit in this number and add them into a list. Now, reverse this list, create the reverse number and print the number backward. Example: User enters 123456, program output will be 654321.
3. Do the above exercise without using a list. Just keep building the reverse number step by step in the same loop where you extract the digits from the original number. And finally display the number you built. (There are smarter ways to do this, but try to do it as directed here, so that you learn the use of While Loop better, ultimately that is our aim).
4. Ask the user to enter a number. Check if it is an even number or odd number. If it is an even number, display all the even numbers starting with zero, up to the number entered by the user. And if the user entered an odd number, display all the odd numbers starting with one, up to the number entered by the user.
5. Ask the user to enter a number. Calculate the sum of the digits in this number. Then use this result as the new number and again calculate the sum of the digits in it. Loop through this process until you end up with a single digit number. This is called the Digit-Sum of the original number. Display the Digit-Sum of the number entered by the user. Example: User enters 456789, program output will be 3. (Hint: You will need to use a nested While Loop here, i.e. a While Loop within another While Loop. The outer loop will repeat the entire process, and the inner loop will extract the digits in a number. You can do it using a single While Loop also, but that will become very complex and untidy.)
๐๐ฒ๐ญ๐ก๐จ๐ง ๐ ๐จ๐ฎ๐ง๐๐๐ญ๐ข๐จ๐ง ๐๐จ๐ฎ๐ซ๐ฌ๐ ๐๐ฎ๐ญ๐จ๐ซ๐ข๐๐ฅ๐ฌ
If you are new to Python or new to programming, you can watch the following tutorials to make a solid foundation in Python. Above all tutorials, remember that practice makes a man perfect. So the more you spend time in writing Python programs, the more knowledge and efficiency you will achieve. I wish you all the best with this programming software and a successful coding experience.
If you have any question on this tutorial, please leave your comment below.
#Python #Programming #Coding