dev-resources.site
for different kinds of informations.
day-12 at payilagam looping exercises
Published at
12/5/2024
Categories
for
while
Author
kuhanraja_ar_1df623b8e2e
Author
24 person written this
kuhanraja_ar_1df623b8e2e
open
1)Write a program to get this output:
1 2 3 4 5 5 4 3 2 1
no = 1
top = 5
direction = 1
while no>0:
print(no,end= ' ')
if no == top:
print(no,end=' ')
direction = -1
no = no + direction
Output:
1 2 3 4 5 5 4 3 2 1
Using Random module:
2) Guess the number game:
Program will run till we guess the number
i
mport random
system_no = random.randint(1,20)
while True:
guess = int(input("Enter the No. "))
if guess == system_no:
print("Hurray! I got the number!! ")
break
elif guess > system_no:
print("Your guess is too high! ")
else:
print("Your guess is too Low! ")
Output:
Enter the No. 5
Your guess is too Low!
Enter the No. 7
Your guess is too Low!
Enter the No. 10
Your guess is too Low!
Enter the No. 12
Hurray! I got the number!!
3) Largest digit in a Number:
no = int(input("Enter no. "))
max_no = 0
while no>0:
rem = no%10
if rem>max_no:
max_no = rem
no//=10
print(max_no)
Output:
Enter no. 452
5
So in 452, 5 is the largest digit in a number.
Tasks:
1) Find Smallest digit in a number:
no = int(input("Enter no. "))
min_no = 9
while no>0:
rem = no%10
if rem<min_no:
min_no=rem
no//=10
print(min_no)
Output:
Enter no. 452
2
2) Find if all digits are equal
no=input("Enter the no. ")
num=1
while num <len(no):
if no[num]==no[0]:
print("All digits are equal")
break
num+=1
else :
print("Not equal")
Output:
1)Enter the no. 4444
All digits are equal
2)Enter the no. 46562
Not equal
for Article's
30 articles in total
day - 16 at payilagam looping slicing stepping task
read article
day - 13 at payilagam puzzles looping
read article
day-15 at payilagam range,index,for
read article
day-12 at payilagam looping exercises
currently reading
enumerate in Python
read article
day -14 at payilagam exercises
read article
day - 9 at payilagam python looping
read article
Why Comfortable Clothing Matters for Developers
read article
zip in Python
read article
python session day-6 at payilagam for loop and if condition
read article
range in Python
read article
Expert Carpet Cleaning Services: Make Your Carpets Look New Again!
read article
Reliable Carpet Cleaning Services: Get Rid of Stains and Odors!
read article
The Ultimate Laptop Buying Guide for Coders in 2025
read article
Ready to Transform Your Career? Join Our Upcoming Online Webinars
read article
Test Automation for Workday Human Capital Management (HCM): Everything You Need to Know
read article
Coding for kids
read article
How To Choose The Best Automation Platform For Testing?
read article
FOR statement in PostgreSQL
read article
FOREACH and FOR statements with arrays in PostgreSQL
read article
What Does Local SEO For Electricians Mean For Your Electrical Company?
read article
Benefits and Challenges of Migrating from Salesforce Classic to Lightning
read article
The Benefits of Migrating Your Salesforce Apps to Lightning
read article
Synergex 7 Reviews 2023 Fake Supplements or Real Results?
read article
Top Benefits of Migrating to Salesforce Lightning
read article
Using for await...of to Iterate Over Synchronous and Asynchronous Arrays in JavaScript
read article
A Comprehensive Guide on Test Automation for Salesforce
read article
How Is Test Automation For Salesforce Beneficial?
read article
For...in Loops...demystified!
read article
Is a Javascript for loop giving you the what-for?
read article
Featured ones: