Python Loops
Python Loops
for i in range(10,50):
if (i%3==0):
print(i)
to find the product of a set of real numbers
i=0
product = 1
count = int(input("Enter the number of real numbers: "))
for i in range(count):
x = float(input("Enter a real number: "))
product = product * x
print("The product of the numbers is: ", product)
Python program to insert a number to any position in
a list
numbers = [3,4,1,9,6,2,8]
print(numbers)
x = int(input("Enter the number to be inserted:
"))
y = int(input("Enter the position: "))
numbers.insert(y,x)
print(numbers)
Python program to delete an element from a list by
index
numbers = [3,4,1,9,6,2,8]
print(numbers)
x = int(input("Enter the position of the element to
be deleted: "))
numbers.pop(x)
print(numbers)
Python Program to Iterate Through Two Lists in
Parallel
list_1 = [1, 2, 3, 4]
list_2 = ['a', 'b', 'c']
rows = 5
for i in range(0, rows):
for j in range(0, i + 1):
print("*", end=' ')
# new line after each row
print("\r")
*
**
***
****
*****
Python program to print the simple number pattern
rows = 6
# outer loop
for i in range(rows):
# nested loop
for j in range(i):
print(i, end=' ')
# new line after each row 1
print('') 22
333
4444
55555
To check the leap year
>>> a, b = 1, 2
>>> a
1
>>> b
2
>>> a + b
3
Check output of the following program.
x=4
y=x+1
x=2
print x, y
a, b = 2, 3
c, b = a, c + 1
print a, b, c
> x = "hello"
>>> y = 'world'
>>> print x, y
hello world
min(2, 3)
2
>>> max(3, 4)
istrcmp('python', 'Python')
True
>>> istrcmp('LaTeX', 'Latex')
True
>>> istrcmp('a', 'b')
False