Form 4 - Computer
2023-2024
Mr. Peter
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/9811262/pasted-from-clipboard.png)
1
2
3
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1490014/images/9343467/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10437733/pasted-from-clipboard.png)
While loop statement - Ex13_1
Save the file as "XX_YYYY_Ex13_1.py"
Summing the Digits of a Number
Write a Python program that asks the user to input a number and then calculates the sum of its digits.
Prompt the user to enter a number.
Extract each digit from the number entered by the user.
Sum all the digits of the number.
Print the result of the sum
Input:
123
Output:
6
Example
While loop statement - Ex13_2
Save the file as "XX_YYYY_Ex13_2.py"
Count the Number of Twos in an Input Number
Create a Python script to count the occurrences of the digit "2" in a user-provided integer. Display the count to the user.
Prompt the user to enter a number.
Iterate through each digit of the number.
Count how many times the digit "2" appears.
Print the counting number.
Input:
2024
Output:
2
Example
While loop statement - Ex13_3
Save the file as "XX_YYYY_Ex13_3.py"
The Largest Digit of the Entered Number
Create a Python script to find the maximum digit of a number entered by a user.
Prompt the user to enter a number.
Iterate through each digit of the number.
Find the largest digit of the entered number.
Print the largest number.
Input:
2024
Output:
4
Example
While loop statement - Ex13_4
Save the file as "XX_YYYY_Ex13_4.py"
The Second Largest Digit of the Entered Number
Create a Python script to find the second largest digit of a number entered by a user.
Prompt the user to enter a number.
Iterate through each digit of the number.
Find the second largest digit of the entered number.
Print the second largest number.
Input:
20391
Output:
3
Example
Python - While Loop
By Mr Peter
Python - While Loop
- 261