- Subhasish Mishra
Python 3 tutorial for beginners in Hindi-Chapter 17(While loop)
Updated: Nov 10, 2020
While Loop in Python
While loop एक known range की दोहराव प्रक्रिया है।
Syntax
while condition:
statement 1
statement 2
other statements
उपरोक्त syntax में यदि condition सही है तो लूप execute करेगा , अन्यथा अन्य स्टेटमेंट execute होंगे।
Write a program to display 1 to 10 numbers using while loop
no =1
while no! = 11:
print(no,end=" ")
no += 1
Output:
1 2 3 4 5 6 7 8 9 10
Write to print the reverse of a number(no)
reverse = 0
while no!=0
r = no%10
n = no//10
reverse =(reverse * 10)+r
print("Reverse of the number is:",reverse)
Write a program to calculate the sum of digits of a number(no)
sum = 0
while no! = 0:
r = no%10
no = no//10
sum =sum +r
print("Sum of digits is:",sum)
Write a program to print the sum of the first & last digit of a number(no).
first_digit = no%10
while no!=0:
last_digit = no%10
no = no//10
print("Sum of the digits is:",first_digit+last_digit)
Write to read 4 digit number(no) &print sum of 2 middle digits
first_digit = no % 10
if x >= 1000 and x <= 9999:
sum = 0
while no!= 0:
r = no % 10
no = no//10
sum += r
print("Sum of middle:"sum-(first_digit-r))
else:
print("please enter 4 digit number")
Write a program to calculate the sum of digits of a number(no) till you get a single digit.
r = 0
sum = 0
while sum<10 and sum>0:
while no!= 0:
r =no%10
no =no//10
sum = sum +r
print("sum")
इस chapter में हमने while loop के बारे में पढ़ा। अगले चैप्टर में input(),recursive function के बारे में पढ़ेंगे।
अगर आपको chapterwise notes chhiye तो निचे कमेंट करे।