0% found this document useful (0 votes)
13 views3 pages

Ex 3 Loops

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Ex 3 Loops

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Programming Lab

Experiment No: 3
Programs on Loops
Objectives: From this experiment, the student will be able to learn
• Basics of Python programming using loops
• How to use transfer statements in python

1. Write a program to print n natural numbers.


2. Write the script to print the numbers from 270 to 225 in reverse order.
3. Write a program to print the multiplication table of n, an integer entered from the
keyboard. Also write a program to print the table from 1 to 10 .
4. Write a program to find the factorial of a number.
5. Write a Python program to find those numbers which are divisible by 7 and multiples of
5, between 1000 and 2000 (both included).
6. Write a program to print the sum of the numbers from 1 to n that are not divisible
by 2,3, and 5.
7. Write a program to find the sum of digits of a given number.
8. Write a program to count the number of digits entered by the user.
9. Write a program to check whether the given number is Armstrong number or not.
Note: An Armstrong number is a number which is equal to the sum of the cubes of
its individual digits. For example, 153, 370, 371, 407 etc. are Armstrong number. 153
is an Armstrong number as − 153 = (1)3 + (5)3 + (3)3
10. Write a while loop that lets the user enter a number. The number should be
multiplied by 10, and the result assigned to a variable named product. The loop
should iterate as long as product is less than 100.
11. Write a code snippet to find the factors of an entered number.
12. Write a code snippet to find an entered number is prime or composite.
13. Write a program to display the reverse of a given number
14. Write a program that asks the user to enter the amount that he or she has budgeted for a
month. A loop should then prompt the user to enter each of his or her expenses for the
month, and keep a running total. When the loop finishes, the program should display the
amount that the user is over or under budget.
15. Write a program for Fibonacci series.
16. Write a program to generate the sum of the series1/1!+1/2!+1/3!+…
17. Write a program to generate the sum of the series1/2+2/3+3/4+…
18. Write a program to find the first even number in a range of integers using break
statement.
19. Write a program that uses nested loops to collect data and calculate the average
rainfall over a period of years. The program should first ask for the number of
years. The outer loop will iterate once for each year. The inner loop will iterate
twelve times, once for each month. Each iteration of the inner loop will ask the
user for the inches of rainfall for that month. After all iterations, the program
should display the number of months, the total inches of rainfall, and the average
rainfall per month for the entire period.
20. Write a program to print the following patterns

a.

b.

c.
Addititonal:

1. Write a program to see if a number is a strong number . A number is called strong


number if sum of the factorial of its digit is equal to number itself.
2. Write a program to print the sum of every 5th number from 0 to 500.
3. Consider a scenario where a son eats five chocolates everyday. The price of each
chocolate is different . His father pays the bill to the chocolate vendor at the end of
every week. Develop a program that can generate the bills for the chocolates and send
to his father.

Viva Questions:

1. Differentiate between counter-controlled loops and sentinel-controlled loops.


2. Explain the concept of an infinite loop and how to avoid it..
3. Which statement is used for writing empty loops? Give an example.
4. Discuss about the use of break and continue statements.
5. What is the role of the else clause in a for or while loop in Python?
6. What is the purpose of the range() function in a for loop? Give its syntax

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy