Python c4 - c7
Python c4 - c7
for i in range(m,n+1):
if(i%2 != 0):
print(i,end=" ")
'''Prime No'''
n=int(input("Enter no: "))
c=0
for i in range(2,n):
if(n%i==0):
print("Not Prime No ");
break;
else:
print("Prime No")
'''
*
**
***
****
*****
'''
'''
*****
****
***
**
*
54321
4321
321
21
1
'''
'''
*****
****
***
**
*
54321
5432
543
54
5
'''
n= int(input("Enter range: "))
for i in range(0, n+1, +1):
for k in range(1, i+1, +1):
print(" ",end="")
print()
'''
*
**
***
'''
n= int(input("Enter range: "))
for i in range (0, n+1, +1):
for k in range(n, i-1, -1):
print(" ",end="")
for j in range(0, i+1, +1):
print("* ",end="")
print()
"""
12345
2
3
4
5
"""
n= int(input("Enter range: "))
for i in range(1, n+1, +1):
if i==1:
for j in range(1, n+1, +1):
print(j,end=" ")
print()
continue
print(i)
"""
*
**
***
**
*
"""
print()
*
*
*
*
*
"""
*
***
******
**********
***************
"""
""" *****
*****
*****
*****
***** """
______
| |
| |
| |
_______
n= int(input("Enter range: "))
for i in range(n):
for j in range(n):
if (i==0 or j==0 or i==n-1 or j==n-1):
print("*",end="")
else:
print(" ",end="")
print()
""" 1
01
101
0101
10101
"""
n= int(input("Enter range: "))
for i in range(1,n+1):
for j in range(1,i+1):
sum= i+j
if(sum%2 == 0):
print("1",end="")
else:
print("0",end="")
print()
"""
* Pattern 1
**
***
****
* Pattern 2
**
***
****
*****
"""
#ASCII
n='A'
m='Z'
print(ord(n)+1)
print(ord('Z'))
for i in range(ord(n),ord(m)+1):
print(chr(i)," ------> ", i)
#Type Casting
n= '12'
n= int(n)
print(type(n))
Python Collection
- LIST-
- Ordered Collection of Item
- Mutable(Can be Modified)
- Created using Square Brackets [] or list() function
- Element can be accessede by index
- It supports Slicing
- It Supports iteration
- It is heterogeneous( different types of data )
my_list= [1,2,3,4,5]
print(my_list)
- TUPLE-
- Ordered Collection of items.
- Imutable(Cannot be Modified)
- Created using Parenthesis ()
- Element can be accessed by Index
- It Supports Slicing
- It is heterogeneous( different types of data )
- It is memory efficient becouse it consume less memory comapare to
list
my_tuple = (1,2,3,4,5)
value= my_tuple[0]
print(value)
- SET-
- Unorderd collection of items
- All the items must be unique & distinct
- Mutable
- Created using Curley Braces {} or set()
- Does not support indexing or slicing.
my_set = {1,2,3,4,5}
my_set2= set([2,3,1,4,5]) #Converting List----> Set
print(my_set == my_set2)
- DICTIONARY-
- Collection of Key-value-pairs
- Mutable
- Created using Curley Braces {} or dict() function
- Element can be accessed only using Keys
- Keys in a dictionary must be unique, but, values can be duplicated
- Supports iteration over Keys, Valyes or Items.