Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Check file size .py

This file was deleted.

12 changes: 12 additions & 0 deletions Deleting_elements_from_a_tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#deleting an element of a tuple
num=(10,20,30,40,50)
print(num)
#accept position number of the element to delete
pos=int(input('Enter position no: '))

#copy from 0th to pos-2 into another tuple num1
num1=num[0:pos-1]

#Concatenate the remaining elements of num fromm pos till end
num=num1+num[pos:]
print(num)
4 changes: 4 additions & 0 deletions Infinite_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i=1
while i<=10:
print(i)
i+=1
10 changes: 10 additions & 0 deletions Insertion_array_element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 29-7-22
# insertion array operation
from array import *

array1 = array('i', [10, 20, 30, 40, 50, 60, 70, ])

array1.insert(9,99)

for s in array1:
print(s)
10 changes: 10 additions & 0 deletions Remove_items_from_a_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#9-7-22
#remove items from a list
def remove(initial_set):
while(initial_set):
initial_set.pop()
print(initial_set)

#Driver code
initial_set = set([10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100])
remove(initial_set)
19 changes: 19 additions & 0 deletions Swap_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Python3 program to swap first
# and last element of a list

# Swap function
def swapList(newList):
size = len(newList)

# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp

return newList


# Driver code
newList = [12, 35, 9, 56, 24]

print(swapList(newList))
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions aliasing_the_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#aliasing an array
from numpy import *
a=arange(1,6)#create a with elements 1to5
b=a #give another name b to a

print('original array: ',a)
print('alias array: ',b)
b[0]=99 #modify 0th element of b
print('after modification: ')
print('original array: ',a)
print('alias array: ',b)
6 changes: 6 additions & 0 deletions arange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#29-1-22
#creating an array with even number up to 10
from numpy import *
#create an array using arrange() function
a=arange(2,11,2)
print(a)
File renamed without changes.
23 changes: 23 additions & 0 deletions array_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#27-1-22
#creating an array
from import array *
a=array.array('i',[5,6,-7,8])
print('the array elements are: ')
for element in a:
print(element)

#creating an array with characters
from array import *
arr= array('u',['a','b','c','d','e'])
print('The array elements are:')
for ch in arr:
print(ch)


#creating an array with characters
from array import *
arr= array('u',['a','b','c','d','e'])
print('The array elements are:')
for ch in arr:
print(ch)

22 changes: 22 additions & 0 deletions array_using_index_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#28-1-22
#searching an array for an element - v2.0
from array import*
#create an empty array to store integers
x=array('i',[])

#store elements into the array x
print('how many elements? ',end=' ')
n=int(input())#accept input into n
for i in range(n): #repeat for n times
print('enter element: ',end=' ')
x.append(int(input())) #add the element to the array x
print('original array: ',x)

print('enter element to search: ',end=' ')
s=int(input())#accept element to be searched
#index() method gives the location of the element in the array
try:
pos=x.index(s)
print('found at position=',pos+1)
except valueerror:# if element not found then valueerror will else\
print('not found in the array')
11 changes: 11 additions & 0 deletions array_using_numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#28-1-22
#creating single dimensional array using numpy
import numpy as np
arr=np.array([10,20,30,40,50])#create array
print(arr) #display array


#creating single array dimensional array using numpy -v3.0
from numpy import *
arr=array([10,20,30,40,50])#create array
print(arr) #display array
18 changes: 18 additions & 0 deletions assertion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#26-3-22
#understanding assert statement
x=int(input('enter a number greater than 0: '))
assert x>0,"wrong input entered"
print('U entered: ',x)




#to handle assertion error raised by assert\
x=int(input('enter a number greater than 0:'))
try:
assert(x>0) # exception may occur here
print('u entered:',x)
except assertionerror:
print("Wrong input entered")# this is executed in case of
#exception

22 changes: 22 additions & 0 deletions attributes_an_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#31-1-22
#the ndim attribute
from numpy import array
arr1=array([1,2,3,4,5])# 1d array
print(arr1.ndim)

arr2=array([[1,2,3],[4,5,6]])
print(arr2.ndim)

#the shape attribute
arr1=array([1,2,3,4,5])
print(arr1.shape)

arr2=array([[1,2,3],[4,5,6]])
print(arr2.shape)

arr2.shape=(3,2) #change shape of arr2 to 3 rows and 2 cols
print(arr2)

# the size attribute
arr1=array([1,2,3,4,5])
print(arr1.size)
File renamed without changes.
33 changes: 33 additions & 0 deletions bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#28-1-22
#sorting an array using bubble short technique
from array import*
#create an empty array to store integers
x=array('i',[])

#store elements into the array x
print('how many elements? ',end=' ')
n=int(input())#accept input into n

#store elements into the array x
print('how many elements? ',end=' ')
n=int(input()) #accept input into n

for i in range(n): #repeat for n times
print('enter element: ',end=' ')
x.append(int(input())) # add the element to the array x
print('original array: ',x)

#bubblesort
flag = False # when swapping is done, flag becomes true
for i in range(n-1): # l is from 0 to n-1
for j in range(n-1-i): # j is from 0 to one element lesser than i
if x[j] > x[j+1]: #it lst element is bigger than the 2nd one
t=x[j]#swap j and j+1 elements
x[j]=x[j+1]
x[j+1]=t
flag=true #swapping done, hence flag is true
if flag==False: #no swapping means array is in sorted order
break #come out of inner for loop
else:
flag=false #assign initial value to flag
print('sorted array= ',x)
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions calender.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Program to display calender of the given month and year
#importing calender Module
import calendar
yy = 2020 #year
mm = 12 #month
yy = 2022 #year
mm = 1 #month
# To take month and year input from the user
# yy = int(input("Enter year:"))
# mm = int(input("Enter month:"))
Expand Down
8 changes: 8 additions & 0 deletions caling_a_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#4-2-22
def sum(a,b):
""" This function finds sum of two numbers """
c=a+b
print('sum= ',c)
#call the function
sum(10,15)
sum(1.5,10.75)
40 changes: 40 additions & 0 deletions check_even_or_prime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
def prime(n):
""" to check if n is prime or not """
x=1
for i in range(2,n):
if n%i==0:
x=0
break
else:
x=1
return x
num=int(input('enter a number: '))
result=prime(num)
if result ==1:
print(num,'is prime')
else:
print(num,'is not prime')

def prime(n):
""" to check if n is prime or not """
x=1
for i in range(2,n):
if n%i == 0:
x=0
break
else:
x=1
return x

num=int(input('How many primes do you want'))
i=2
c=1
while True:
if prime(i):
print(i)
c+=1
i+=1
if c>num :
break


13 changes: 13 additions & 0 deletions check_file_size .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Get file size , print it , process it...
#Os.stat will provide the file size in (.st_size) property.
#The file size will be shown in bytes.

import os

fsize=os.stat('filepath')
print('size:' + fsize.st_size.__str__())

#check if the file size is less than 10 MB

if fsize.st_size < 10000000:
processing is:
7 changes: 7 additions & 0 deletions checking_membership.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#2-2-22
str=input('enter main string: ')
sub=input('enter main string: ')
if sub in str:
print(sub+'is found main string')
else:
print(sub+'is not found in the main activity')
11 changes: 11 additions & 0 deletions cloning_or_copying.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#19-7-22
#cloning or copying
def cloning(list1):
list_copy=[]
list_copy=list1
return list_copy
#Drivercode
list1=[10,15,20,25,30,35,40,45,50]
list2=cloning(list1)
print("original list: ",list1)
print("After cloning: ",list2)
4 changes: 2 additions & 2 deletions command line arguments.py → command_line_arguments.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#find sum of even numbers
import sys
#read command line arguments except the program name
args=sys.args[1:]
args=sys.argv[1:]
print(args)
sum=0
#find sum of even arguments
for a in args:
x=int(a)
ifx%2=0
if x%2==0:
sum+=x
print('sum of events=',sum)
Loading