diff --git a/basics.py b/basics.py new file mode 100644 index 0000000..2e8f7d6 --- /dev/null +++ b/basics.py @@ -0,0 +1,213 @@ +# print("Hello Basics From python") +# print("asif",24,sep='-',end='\n') +# print("Hello","World",24,True,end='',sep='') + +#single line comment +"""High +This is a +multi line +comment""" +import sys +#data types - numeric(int,float,boolean,complex) +# int_var = 24433432849486984 +# print(int_var,type(int_var)) +# print(sys.getsizeof(int_var)) + +# float_var = 12342242242242.24225223243224424 +# print(float_var,type(float_var)) +# print(sys.getsizeof(float_var)) + +# bool1 = True +# bool2 = False + +# print(bool1,type(bool1)) +# print(sys.getsizeof(bool1)) +# print(bool2,type(bool2)) +# print(sys.getsizeof(bool2)) + +# complex1 = 2 + 3j +# complex2 = complex(2,3) +# print(complex1,type(complex1)) +# print(sys.getsizeof(complex1)) + +#sequence typed - string,list,tuple +# str1 = "Hello Asif" +# print(str1,type(str1)) +# str2 = str(23) +# print(str2,type(str2)) +# print("\n") +# l1 = [12,3,342,42] +# t1 = (12,32,1132,23) +# print(l1,type(l1)) +# print(t1,type(t1)) + +# s = {12,3,22,324,2} +# print(s,type(s)) + +# dict1 = {"name":"Asif","age":24} +# print(dict1,type(dict1)) + +# a = None +# print(a,type(a)) + +# a = 23 +# print(a) +# a = "Asif" +# print(a) +# a = True +# print(a) + +# a,b,c = 23,34,22 +# print(a,b,c) + +# #keywords - for,if,else + +# a = b = c = 100 +# print(a,b,c) +# print(id(a),id(b),id(c)) + +# name = input("What's your name:") +# print("Your name is:",name) + +#type conversion +# var1 = int(123) +# # var2 = int("Asif") +# var2 = int(12.232) +# print(var1,var2) + +# var3 = float(23) +# print(var3) + +# print("23"+23) + +# print("Data","Science","Mentorship","Progran","By","CampusX",sep='-',end="\n") + +# celcius = float(input("Enter celcius value:")) +# farenheit = (9 * celcius)/5 + 32 +# print("In farenheit:",farenheit) + +# num1 = int(input("enter a number:")) +# num2 = int(input("enter another number:")) + +# temp = num1 +# num1 = num2 +# num2 = temp +# print(f"After swapping:{num1},{num2}") + +# x1 = float(input("Enter x1:")) +# y1 = float(input("Enter y1:")) +# x2 = float(input("Enter x2:")) +# y2 = float(input("Enter y2:")) + +# euc_distance = ((x1-x2)**2 + (y1-y2)**2)*0.5 +# print("distance is :",euc_distance) + +#simple interest calculator +# p = int(input("Enter amount:")) +# r = float(input("Enter rate of interest:")) +# t = int(input("Enter time")) + +# interest = p * r * t +# print("Interest is:",interest-p) + +# heads = int(input("Heads-> ")) +# legs = int(input("Legs ->")) + + +#literal - constant value that is stored in variable +a = 2 +a = 0b1010 + +# print(a) + +# b = 0o456 +# print(b) +# c =0xA234 +# print(c) + +# f1 = 10.34 +# f2 = 12e-3 +# f3 = 1e5 +# print(f1,f2,f3) + +# complex1 = 4 + 3j +# print(complex1) + +# a = None +# print(a) +# b = True +# print(b +3) + + +#question no 6 +# heads = int(input("heads->")) +# legs = int(input("legs->")) + +# dogs = (legs - 2 * heads)/2 +# chickens = heads - dogs + +# print() + +#question 7 +# num = int(input("Enter n :")) +# sum = (num * (num+1)*(2*num+1))/6 +# print("Sum is:",sum) + +#question 8 +# num1 = int(input("enter 1st num:")) +# num2 = int(input("enter 2nd num:")) +# n = int(input("Enter n:")) +# diff = num2 - num1 + +# a = num1 + (n-1)*diff +# print(a) + +#question 9 + +# x1 = int(input("Enter x1:")) +# y1 = int(input("Enter y1:")) +# x2 = int(input("Enter x2:")) +# y2 = int(input("Enter y2:")) + +# num = x1 * y2 + y1 * x2 +# den = y1 * y2 + +# print("{}/{}".format(num,den)) + +#question 10 +# print("Dimentions of the milk tank") +# H = int(input("H = ")) +# L = int(input("L = ")) +# B = int(input("B = ")) +# print("Dimensions of the glass") +# h = int(input("h = ")) +# r = int(input("r = ")) + +#literals +# int_val = 103343 +# bin_val = 0b1001 +# dec_val = 0o234 +# hex_val = 0xA23 +# print(bin_val,type(bin_val)) +# print(dec_val,type(dec_val)) +# print(hex_val,type(hex_val)) + +# f1 = 1232.4323 +# f2 = 2232e2 +# f3 = 232e-3 +# print(f1,type(f1)) +# print(f2,type(f2)) +# print(f3,type(f3)) + +# a = 7 + 4j +# b = complex(3,4) +# print(a,type(a),b,type(b)) + +# bool1 = True +# bool2 = False +# print(bool1 + 4) +# print(bool2 - 4) + +a = None +print(a,type(a)) +a = 100 diff --git a/error_handling.py b/error_handling.py new file mode 100644 index 0000000..c7c2847 --- /dev/null +++ b/error_handling.py @@ -0,0 +1,49 @@ +print("Syntax Error") +# print "a" +# print "Hello World" +# marks = 80 +# if marks>=80: +# print("A+") +# if True + # print("Asif") +# fo i in ran(5): +# class A: + +#index error +# l=[1,2,3,4,5] +# print(l[50]) + +#module not found error +# import mata +# print(math.floor(10.4)) + +#key error +# dict1 ={"name":"Asif"} +# print(dict1["age"]) + +#typeerror +# print(1 +"a") + +#valueerror + + + + +#exceptions +# with open('sample.txt','w') as f: +# f.write("Hello World") + +# with open('sample.txt','r') as f: +# print(f.read()) + +# try: +# with open('sample1.txt','r') as f: +# print(f.read()) +# except: +# print("File not found") + +try: + with open('sample.txt','w') as f: + f.read() +except: + print("Operation failed") \ No newline at end of file diff --git a/file-handling.py b/file-handling.py new file mode 100644 index 0000000..fb1ef0d --- /dev/null +++ b/file-handling.py @@ -0,0 +1,184 @@ +#if file is not present +# f = open('./sample.txt','w') +# f.write("Hello World") +# f.close() +# f.write("Asif") + +# f = open('./file-1.txt','w') +# f.write("Hello World") +# f.close() +# f.write("My name is Asif") + +#write multiline string +# f = open('./sample1.txt','w') +# f.write("Hello Emon\nThis is file 1") +# f.write('\n') +# f.write("I am 24 years old") +# f.write("\n") +# f.write("Closing file") +# f = open('./file-2.txt','w') +# f.write('Hello World') +# f.write('\n') +# f.write('I am 24 years old') +# f.close() +#if file is already present +# f = open("./sample.txt",'w') +# f.write("Salmon Bhai is my favourite") +# f.close() + + + +#append mode +# f = open('sample1.txt','a') +# f.write("Salmon bhai is my favourite") +# f.close() +# f = open('./sample1.txt','a') +# f.write("\n") +# f.write("Salmon bhai is the don") +# f.close() + +# for i in range(1,11): +# f = open('./sample1.txt','a') +# f.write(f"Hello {i}\n") +# f.close() + +#write many lines +# l = ['Hello\n','i am\n','Asif\n','Arfi\n'] +# f = open('./file-2.txt','w') +# f.writelines(l) +# f.close() +# obj1 = 'Hello Python' +# f = open('./file-2.txt','a') +# f.writelines(obj1) +# f.close() + +#reading from files - read(),readline() +# f = open('./file-2.txt','r') +# s = f.read() +# print(s) +# f.close() +# f = open('file-2.txt','r') +# print(f.readline()) +# print(f.readline()) +# s1 =f.readline() +# s2 =f.readline() +# print(s1) +# print(s2) +# f.close() + +#reading upto n characters +# f = open('./sample.txt','r') +# print(f.read()) +# f = open('./sample1.txt','r') +# print(f.read(20)) +# f.close() + +print("File handling revise") + +#if file is not present +# f = open('sample.txt','w') +# f.write("Hello Asif") +# f.close() +# f.write("I am writing something") + +#write multiline strings +# f = open('sample.txt','w') +# f.write("Asif") +# f.write("Emon") +# f.write("\nProbin") +# f.close() + +#case-2 : if the file is already present +# f = open('sample.txt','w') +# f.write("Hello Asif") +# f.write("\nI am 24 years old") +# f.close() + +# f = open('sample.txt','a') +# f.write('I am appending') +# f.write("How are you?") +# f.close() + +print("hi") + +# l = ["1","2","3","4","5"] +# t = ('Asif','emon','hasan') +# s = "\nASIF" +# # n = 1231 +# f = open('sample.txt','a') +# f.writelines(l) +# f.writelines(t) +# f.writelines(s) +# f.writelines(n) + + +#reading from files-read/readlines +# f = open('sample.txt','r') +# d = f.read() +# print(d) +# d1 = f.readline() +# d2 = f.readline() +# print(d1,d2) + + +# f = open('loop.txt','a') +# for i in range(1,11): +# f.write(f"Hello from {i}\n") +# f.close() + +# f = open('loop.txt','r') +# data = f.read() +# print(data) + +# f = open('loop.txt','r') +# d1 =f.readline() +# d2 =f.readline() +# d3 =f.readline() +# print(d1) +# print(d2) +# print(d3) + +# f = open('loop.txt','r') +# d =f.read(100) +# print(d) + +# print("hello") + +# f = open('loop.txt','r') +# l1 = f.readline() +# l2 = f.readline() +# print(l1) +# print(l2) + +#reading entire file using readline +# f = open('loop.txt','r') +# while True: +# data = f.readline() +# if data =='': +# break +# else: +# print(data,end='') + +# f.close() + +# f = open('file-2.txt','r') +# while True: +# data = f.readline() +# if data =='': +# break +# else: +# print(data,end='') + +# f.close() + +# with open('file-2.txt','a') as f: +# f.write("Salmon bhai") +# f.write("Hello") +# with open('file-2.txt','r') as f: +# data =f.read() +# print(data) + +# with open('file-2.txt','r') as f: +# data = f.readline() +# print(data) + diff --git a/functions.py b/functions.py new file mode 100644 index 0000000..090be4d --- /dev/null +++ b/functions.py @@ -0,0 +1,119 @@ +#functions and methods +print("Functions") +# def sum(): +# """ +# calculates sum +# input - no input +# output - sum of two numbers +# created by - asif +# """ +# a = 10 +# b = 20 +# print(a+b) + +# sum() + +# print(print.__doc__) +# print(sum.__doc__) +# print(type.__doc__) + +# def is_even(num): +# """ +# fn to calculate even/odd numbers +# input - any valid integer +# output - even/odd +# created - name date +# """ +# if type(num) == int: +# if num % 2 ==0: +# return "Even" +# else: +# return "Odd" +# else: +# return "Wrong value passed" +# for i in range(1,11): +# print(is_even(i)) + +# print(is_even("Asif")) +# print(is_even.__doc__) + +# arguments +# def sum (a=10,b=20): +# return a + b +# print(sum(10)) +# def sub(a=0,b=0): +# return a - b +# print(sub(50,20)) + +# l = [1,2,3] +# print(l.append(4)) + +#variable scope +# def g(y): +# print(x) +# print(x+1) +# x = 5 +# g(x) +# print(x) +# def f(y): +# x = 1 +# x += 1 +# print(x) +# x = 5 +# f(x) +# print(x) +# def h(y): +# x += 1 +# x = 5 +# h(x) +# print(x) + +# l1 = [1,2,3,4,5,6,7,8,9] +# l2 = [] +# for i in l1: +# if i % 2 ==0: +# l2.append(i) +# print(l2) + +# def outer(): +# print("outer function") +# def inner(): +# print("inner function") +# inner() +# outer() +# inner() +# def g(x): +# def h(): +# x = 'abc' +# x = x + 1 +# print('in g(x): x =', x) +# h() +# return x + +# x = 3 +# z = g(x) +# print(z) + +# def g(x): +# def h(x): +# x = x+1 +# print("in h(x): x = ", x) +# x = x + 1 +# print('in g(x): x = ', x) +# h(x) +# return x + +# x = 3 +# z = g(x) +# print('in main program scope: x = ', x) +# print('in main program scope: z = ', z) +# l1 = [1,2,3,3,3,3,4,5] +# l2 = [] +# for i in range(len(l1)-1,-1,-1): +# for j in range(0,i): +# if l1[i] == l1[j]: +# continue +# else: +# l2.append(l1[j]) +# print(l2) + diff --git a/list.py b/list.py new file mode 100644 index 0000000..157f7ed --- /dev/null +++ b/list.py @@ -0,0 +1,255 @@ +print("List and methods") + +# l = [10,"Asif",25.99,True] +# print(id(l[0])) +# print(id(l[1])) +# print(id(l[2])) +# print(id(l[3])) + +#characteristics of list +# l = [1,2,3,4] +# print(l[1]) +# print(l[-1]) +# print(l[0]) + +# l = [12,34,22] +# l[0] = 10 +# print(l) + +# l = [12,"Asif",23.44] +# print(l) + +# l = [12,34,12] +# print(l) +# l.append(100) +# print(l) +# l = [12,10,[12,12]] +# print(l) + +# l = [(1,2),"Asif",{"name":"Asif"}] +# print(l) + +# ulti_list = [10,[20,30],"Asif",True,(5,6),{"age":24}] +# print(ulti_list[0]) +# print(ulti_list[-1]) +# ulti_list[0] = 100 +# print(ulti_list) +# l1 = [12,3,43] +# l2 = [12,3,43] +# print(l1 == l2) +# print(l1 is l2) + +#creating a list +# l1 = [] +# print(l1) +# l2 = ["Asif","Probin","Hasan"] +# print(l2) +# l3 = [12,34,[1,2],[2,3]] +# print(l3) +# print(l3[2][0]) +# l4 = ["Asif",24,True] +# print(l4) +# l5 = [[1,2,[5,6]],[0,10,[20,30]]] +# print(l5[0][2][0],l5[1][2][1]) +# li = list("Asif") +# print(li) +# l1 = list((12,34,55)) +# print(l1) +# l2 = list([12,34,[1,2]]) +# print(l2) +#accessing items from a list +l = [10,20,30,40,50] +# print(l[0]) +# print(l[3]) +# print(l[-1]) +# print(l[len(l)-4]) +# print(l[::]) +# print(l[::-1]) +# print(l[1:4]) +# print(l[0:3]) +# print(l[-5:-1:]) + +#adding items on a list-append,insert,extend +# l = [10,20,30,40,50,60] +# print(l.append(70)) +# print(l) +# l.extend("Asif") +# print(l) +# l.extend([1,2,3]) +# print(l) +# l.insert(0,'Asif') +# print(l) + +# l1 = [10,20,30,40] +# l1.insert(1,200) +# l1.insert(-1,[1,2]) +# print(l1) +# l1.append(100) +# print(l1) +# l1.extend("Asif") +# print(l1) + +#editing items on a list +# l = [1,2,3,4,5,6,7] +# l[0] = [12,34] +# print(l) +# l[1] = 100 +# print(l) +# l[0:3]=[1,2,3] +# print(l) + +#deleting items from a list - pop,del,remove,clear +l = [10,20,30,50,40] +# l.pop() +# print(l) +# l.pop(0) +# print(l) +# del l[0] +# print(l) +# del l[0:2] +# print(l) +# print(l.pop()) +# l.remove(20) +# print(l) +# print(l.remove(40)) +# print(l) +# l.clear() +# print(l) +# print(l) +# del l +# print(l) +# del l[0] +# print(l) +# del l[0:2] +# print(l) +# l.pop() +# print(l) +# l.pop(1) +# print(l) +# l.remove(50) +# print(l) +# l.clear() +# print(l) + +#operation on list +#arithmetic - +,* +# l1 = [1,2,3] +# l2 = [4,5,6] +# print(l1+l2) +# print(l1*4) + +#list revise +# l = [12,"Asif",True,10,[1,2,3]] +# print(id(l[0])) +# print(id(l[1])) +# print(id(l[2])) + +# l[0] = 10 +# print(l) +#nested list +# l = [10,20,30,[1,2,3,[5,6]]] +# print(l[3][3][1]) +# l = list([1,2,3,4]) +# print(l) + +#accessing list items- index,slicing +l1 = [10,"Asif",True,(1,2,3)] +# print(l1[0]) +# print(l1[-2]) +# print(l1[len(l1)-3]) + +# print(l1[::-1]) +# print(l1[::]) +# print(l1[1:3]) +# print(l1[-1:-3:-1]) + +#adding items to a list-append,extend,insert +list1 = [10,20,30,40] +# list1.append(50) +# list1.append([1,2,3]) +# list1.append(("Asif")) +# list1.append("Asif") +# print(list1) +# list1.extend("Asif") +# print(list1) +# list1.extend([1,2,3]) +# print(list1) +# list1.insert(0,"Asif") +# print(list1) + +#editing items on a list +#list is mutable - can change any particular value +# l = [10,"Asif",24.5,True,1,2] +# l[0] = 100 +# print(l) +# l[1:3]=["Asif"] +# print(l) + +#deleting items from a list +# del l[0] +# print(l) +# del l[1:3] +# print(l) +# del l +# print(l) + + + + +#problem 1 +# list1 = ["M","na","i","Kh"] +# list2 = ["y","me","s","an"] +# list3 = [] + +# for i in range(0,len(list1)): +# item = [] +# item.append(list1[i]) +# item.append(list2[i]) +# list3.append(item) + +# print(list3) + +#problem - 2 +# list1 = [10,20,[300,400,[5000,6000],500],30,40] + +# for item in list1: +# if isinstance(i,list): +# for j in i: + + + +#problem - 4 +# list1 = [1,2,3,4,5,6] +# list2 = [] +# sum = 0 +# for i in list1: +# sum +=i +# list2.append(sum) + +# print(list2) + +#problem - 3 +# candy_list = ['Jelly Belly','Kit Kat','Double Bubble','Milky Way','Three Musketeers'] +# no_of_items = [10,20,34,74,32] + +# for i in range(0,len(candy_list)): +# print(f"{candy_list[i]}- {no_of_items[i]}") + +#problem - 10 +# list1 = ['campusxIs', 'bestFor', 'dataScientist'] +# for item in list1: +# for char in item: +# if char.upper() + +#problem - 11 +# list1 = [1,2,3,4,5,1] +# list2 = [2,3,5,7,8] +# list3 = [] + +# for i in range(0,len(list1)): +# if list1[i] == list2[i]: +# list3.append(list1[i]) +# else: +# list3.append(list2[i]) + +#list revise diff --git a/main.py b/main.py deleted file mode 100644 index 1fb16de..0000000 --- a/main.py +++ /dev/null @@ -1,50 +0,0 @@ -print("Section 4 : Operators and expression") -#arithmetic operatord(+,-,*,/,//,%,**) -num1 = 40 -num2 = 30 -# add = num1+num2 -# sub = num1-num2 -# multi = num1*num2 -# div = num1/num2 -# print(add,sub,multi,div) -# floor = num1//num2 -# mod = num1%num2 -# print(floor) -# print(mod) -# a,b,c=2,2,3 -# d = a**b**c -# print(d) -#floating point numbers -# a = 25.3 -# b = 6.4 -# floor = a//b -# mod = a %b -# sub = a - b -# print(floor,mod,sub) -#expression - something that results in values -# a,b,c = 10,45,22 -# x = a * b +c -# print(x) -#operator precedence (),** (right to left),*/ // %,+,-(left to right) - -# x = (10+20)*2-4 -# print(x) -# a=b=c=3 -# print(a**b**c) -# print(20-5*3/3+10) -# print(10+20/5) -#area of a rectangle -# length = int(input("Enter length:")) -# width = int(input("Enter width:")) -# area = length*width -# print("area is:",area) -#area of a triangle -# height = int(input("Enter height:")) -# base = int(input("Enter base:")) -# area = int(0.5 * height * base) -# print("area is",area) -#area of a trapezium -# len = int(input("Enter length:")) -# wid = int(input("Enter width:")) -# hei = int(input("Enter height:")) -# area = \ No newline at end of file diff --git a/oop1.py b/oop1.py new file mode 100644 index 0000000..0ba8af0 --- /dev/null +++ b/oop1.py @@ -0,0 +1,148 @@ +print("Python object oriented programming") + +# l = [1,2,3] +# l.upper() + +#oop - class ,object,encapsulation,inheritance,polymorphism,abstraction + +# l = [1,2,3] +# print(type(l)) + +#class - property/attribute - blueprint of object +# class Student: +# def __init__(self) + +# st1 = Student() +# class Human: +# def __init__(self): +# print("Human object created") + +# asif = Human() + +# class Student: +# def __init__(self): +# self.name = "Asif" +# self.age = 25 +# self.course ="CSE" +# print(f"name:{self.name} age:{self.age} course:{self.course}") + +# stu_asif = Student() + +# class Student: +# def __init__(self,name,age,course): +# self.name = name +# self.age = age +# self.course = course +# print(f"name:{self.name} age:{self.age} course:{self.course}") + +# student1 = Student("Probin",24,"EEE") +# student2 = Student("Asif",25,"CSE") +# print(type(student1)) + +# class Atm: +# def __init__(self): +# self.balance = 0 +# self.pin ="" +# self.menu() + +# def menu(self): +# user_input=input("""Hi +# How can i help you? +# 1.Press 1 to create pin +# 2.Press 2 to change pin +# 3.Press 3 to debit balance +# 4.Press 4 to withdraw balance +# 5.Press 5 to check balance +# 6.Press 6 to exit\n""") + +# if user_input =="1": +# self.create_pin() +# elif user_input =="2": +# self.change_pin() +# elif user_input =="3": +# self.credit_balance() +# elif user_input =="4": +# self.withdraw_balance() +# elif user_input =="5": +# self.check_balance() +# else: +# self.menu() + +# self.menu() + +# def create_pin(self): +# user_pin = input("Enter pin:") +# self.pin = user_pin +# print("Pin created successfully") + +# def change_pin(self): +# user_pin = input("Enter your pin:") +# if user_pin == self.pin: +# new_pin = input("Enter new pin:") +# self.pin = new_pin +# print("New pin created") +# else: +# print("Wrong pin") + +# def credit_balance(self): +# user_pin = input("Enter your pin:") +# if user_pin == self.pin: +# balance = int(input("Enter your balance:")) +# self.balance = balance +# print("Balance credited successfully") +# else: +# print("Wrong pin") + +# def withdraw_balance(self): +# user_pin = input("Enter your pin:") +# if self.pin == user_pin: +# withdraw_balance = int(input("Enter amount to withdraw:")) +# if withdraw_balance < self.balance: +# self.balance = self.balance - withdraw_balance +# print(f"{withdraw_balance} withdrawn successfully") +# print(f"current balance is:{self.balance}") +# else: +# print("You don't have thar much balance") + +# else: +# print("Wrong pin") + + +# def check_balance(self): +# print("current balance is {}".format(self.balance)) + + +# obj = Atm() + +# class Student: +# def __init__(self,name,age,course): +# self.name = name +# self.age = age +# self.course = course + +# def read(): +# print() + +# class Car: +# def __init__(self): +# print(id(self)) + +# def __str__(self): +# print("Object got created") + +# bmw = Car() +# print(id(bmw)) +# # print(bmw) + +# class Car: +# def __init__(Self,name,model): +# Self.name = name +# Self.model = model + +# def __str__(Self): +# return f"Car name:{Self.name} model:{Self.model}" + +# bmw =Car("BMW","X6") +# print(bmw) +# audi = Car("Audi","R8") +# print(audi) \ No newline at end of file diff --git a/operators.py b/operators.py new file mode 100644 index 0000000..3ae8b03 --- /dev/null +++ b/operators.py @@ -0,0 +1,357 @@ +print("Operators in python") + +#operators - symbols to carry out calculations +# a(operand) +(operator) b(operand) + +# a = 100 +# b = 50 +# sum = a + b #150 +# sub = a - b #50 +# multi = a * b #5000 +# div = a / b #2.0 +# exp = a ** b #large number +# floor_div = a // b #2 +# mod = a % b #0 + +# print(sum) +# print(sub) +# print(multi) +# print(div) +# print(exp) +# print(floor_div) +# print(mod) +#operator precedence-(),**,/ * % //,+- +print(20 + (3*4) - 2 *4 /4) +# print(2**3**2) + +#relational operator - to compare between two things +# print(4>5) #false +# print(10<34) #true +# print(4>=4) #true +# print(5<=4) #false +# print(4 == 4) #true +# print(10 !=30) #true +# print(2 == 2.00) + + +#logical -and,or,not +# print(12 and "Asif") +# print("" and 200) + +# print(12 or 13 or 23) +# print("" or 20 or 23) + +# print(not 12) + +#bitwise operator - bit by bit kaj kore +# print( 10 & 4) +# print(5 & 5) +# print(10 ^ 5) +# print(~4) + +#assignment operator- =+,=-,*=,/= +# a = 10 +# b = 5 +# a+=b +# print(a) +# a-=b +# print(a) +# a*=b +# print(a) + +# a /=b +# print(a) +# a %=b +# print(a) +# # a++ +# ++a +# print(a) +# print(a) + +#membership operator-in,not in +l = [1,2,3,4] +str1 = "Hello World" +t = ("Asif",25,True) + +# print(1 in l) +# print(10 not in l) +# print("A" in str1) +# print("o" not in str1) +# print(25 in t) +# print(False not in t) + +# num = int(input("Enter a number:")) +# dig1 = num % 10 +# num = num //10 +# dig2 = num % 10 +# num = num //10 +# dig3 = num %10 +# num = num //10 +# dig4 = num % 10 +# print(dig1+dig2+dig3+dig4) + +#identity operator- is,is not +# print(12 is 12) +# print(12 is not 12) + +#if else in python +#login process +# email = input("Enter you email:") +# password = input("Enter password:") + +# if email =="asif@gmail.com" and password =="1234": +# print("login successful") +# elif email == "asif@gmail.com" and password !="1234": +# print("Wrong password") +# password = input("Enter password:") +# if password =="1234": +# print("Login success") +# else: +# print("Wrong info") + +#find the min of 3 given numbers +# num1 = int(input("Enter a number:")) +# num2 = int(input("Enter a number:")) +# num3 = int(input("Enter a number:")) + +# if num1 < num3 and num1 < num2: +# print(f"{num1} is the min") +# elif num2 < num1 and num2 < num3: +# print(f"{num2} is the min") +# else: +# print(f"{num3} is the min") + +#match case statement +# x = "monday" +# match x: +# case "Sunday": +# print("Today is sunday") +# case "Monday": +# print("Today is monday") +# case "Tuesday": +# print("Today is tuesday") +# case _: +# print("Invalid day") + + + +#operator tasks +# ctc = int(input("Enter ctc:")) +# hra = ctc * 0.1 +# da = ctc * 0.05 +# pf = ctc * 0.03 +# salary = ctc - (hra + da + pf) +# if ctc<5: +# salary = salary +# elif ctc >=5 and ctc < 10: +# tax = ctc*0.1 +# salary = salary - tax +# elif ctc >=10 and ctc <20: +# tax = ctc *0.2 +# salary = salary - tax +# elif ctc >=20: +# tax = ctc * 0.3 +# salary = salary - tax + +#problem - 2 +# angle1 = float(input("enter a angle:")) +# angle2 = float(input("enter a angle:")) +# angle3 = float(input("enter a angle:")) + +# if (angle1+angle2) > angle3 or (angle2 + angle3) >angle1 or (angle3+angle1) >angle2: +# print("Can be a triangle") +# else: +# print("Cannot form a triangle") + +# sum_of_angles = angle1 + angle2 + angle3 +# if sum_of_angles == 180 and (angle1>0 and angle2>0 and angle3>0): +# print("Can be a triangle") +# else: +# print("Can't be a triangle") + +# cost = float(input("Enter cost price:")) +# sell = float(input("Enter selling price:")) + +# if cost > sell: +# print("Loss") +# elif cost < sell: +# print("Profit") +# else: +# print("Even") + +#problem 4 - menu driven program +# while True: +# user_input = input(""" +# 1.cm to ft +# 2.km to miles +# 3.USD to BDT +# 4.exit\n""") + +# if user_input == '1': +# cm = float(input("Enter cm value:")) +# fit = cm /30.48 +# print(f"{cm} cm = {fit} ft") +# elif user_input =="2": +# km = float(input("Enter km value:")) +# miles = km /1.61 +# print(f"{km} km = {miles} miles") +# elif user_input == "3": +# usd = float(input("Enter usd:")) +# bdt = usd * 122.27 +# print(f"{usd} usd = {bdt} bdt") +# else: +# print("Exited") +# break + +#problem 5 - fibonacci sequence +# ini = 0 +# mid = 1 +# for i in range(1,10): + + +#problem 6 +# n = int(input("Enter a number:")) +# fact = 1 +# for i in range(1,n+1): +# fact *= i + +# print(f"factorial of {n} is : {fact}") + +#problem 7 +# n = 76542 +# s ="" +# while n % 10 != 0: +# dig = n % 10 +# s +=dig +# n = n // 10 +# print(s) + +#problem 8 +# N = int(input()) +# sum = 0 +# i = 0 +# while i < N : +# if i % 5 == 0: +# continue +# else: +# sum += i + +# i +=1 + + + +#control flow +#operators +# exp1 = 34.5 + 45 +# #arithmetic(+,-,*,/,%,//,**) +# add = 234.5 + 45 +# sub = 23 - 45.0 +# multi = 34 * 45.0 +# div = 45 / 4 +# mod = 34 % 5 +# flo_div = 23 // 10 +# print(add,sub,multi,div,mod,flo_div) +#precedence - (), **,* / // %,+ - +#relational operator - ><>=<=.==,!= +# print(45 > 33) +# print(34 < 23) +# print(34>=45) +# print(44<=23) +# print(12 == 12) +# print(12 is 23) +# print(12.0 == 12) +# l1 = [12,3,4] +# l2 = [12,3,4] +# print(l1 is l2) +# print(l1 == l2) +s1 = "Asif" +s2 = "Asif" +# print(s1 == s2) +# print(s1 is s2) +t1 =(1,2,3) +t2 =(1,2,3) +# print(t1 == t2) +# print(t1 is t2) +#assignment - +=,-= +# a = 30 +# a+=30 +# print(a) +# a-=40 +# print(a) +# a*=30 +# print(a) +# a /= 15 +# print(a) +# a %= 3 +# print(a) +#logical operator - and,or,not +# print(true and true) +# print("Asif" and "23") +# print("" and 23) + +# print(23 or 12) +# print("" or "Asif") + +#membership operator-in,not in +# print(4 in [1,2,3]) +# print(5 not in (1,234)) +#if else + +#palindrome number +# num = int(input("Enter a number:")) +# num_str = str(num) +# num_rev = num_str[::-1] +# if num_str == num_rev: +# print("Palindrome") +# else: +# print("Not palindrome") + + +#sum of digits +# num = int(input("Enter a number:")) +# sum = 0 +# while num % 10 !=0: +# dig = num % 10 +# sum += dig +# num = num // 10 +# print(sum) + +#count even and odd digits +# num = int(input("Enter a number:")) +# even = 0 +# odd = 0 +# while num % 10 !=0: +# dig = num % 10 +# if dig % 2 ==0: +# even += 1 +# else: +# odd += 1 +# num = num // 10 +# print("Even digits:{}".format(even)) +# print("Odd digits:{}".format(odd)) + +#largest of 3 numbers +# num1 = int(input("Enter a number:")) +# num2 = int(input("Enter a number:")) +# num3 = int(input("Enter a number:")) +# if num1 > num2 and num1 > num3: +# print(f"{num1} is the largest") +# elif num2 > num3: +# print(f"{num2} is the largest") +# else: +# print(f"{num3} is the largest") + +#electricity bill calculator +# units = float(input("Enter units:")) +# bill = 0 +# if units >=0 and units<=100: +# price = 5 +# bill_under_100 = units * 5 + +# if units >=101 and units <= 200: +# price = 7 +# bill_under_200 = bill_under_100 + + +#multiplication table of n +n = int(input("Enter :")) + diff --git a/poridhi-mod1.py b/poridhi-mod1.py deleted file mode 100644 index afa491b..0000000 --- a/poridhi-mod1.py +++ /dev/null @@ -1,13 +0,0 @@ -#extract digits from a number -n = 7890 -res =[] -count =0 -while n!=0: - dig = n %10 - count = count + 1 - res.append(dig) - n = n//10 - -res.reverse() -print(res) -print("Digits:",count) \ No newline at end of file diff --git a/python-file1 b/python-file1 deleted file mode 100644 index 1185e18..0000000 --- a/python-file1 +++ /dev/null @@ -1 +0,0 @@ -here is a file to explore how to pull locally diff --git a/readme.md b/readme.md index ec8e50e..1fa5575 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,10 @@ +#Python Pratice Code Here is a readme file to explore pull request +Here is a readme line for practicting git merge + +#heading1 +##heading2 +###heading3 +####heading4 +#####heading5 +######heading6 diff --git a/section1.py b/section1.py deleted file mode 100644 index 96b0c89..0000000 --- a/section1.py +++ /dev/null @@ -1,26 +0,0 @@ -# print("Getting started") -# message = "Hello Python" -# print(message) -print("Python data types and variables") -# int_var = 10 -# float_var = 34.56 -# str_var = "Asif" -# bool_var = True -# print(int_var,type(int_var)) -# print(float_var,type(float_var)) -# print(str_var,type(str_var)) -# print(bool_var,type(bool_var)) -#assigning multiple values -# a,b,c = 10,"Python",False -# print(a,b,c) -# print(id(a),id(b),id(c)) -# a=b=c=10 -# print() -dig = 7895 -ls =[] -while dig!=0: - last_dig = dig % 10 - ls.append(last_dig) - dig = dig //10 - -print(ls) \ No newline at end of file diff --git a/section3.py b/section3.py deleted file mode 100644 index 476902d..0000000 --- a/section3.py +++ /dev/null @@ -1,129 +0,0 @@ -import sys -print("Variables and Data types") -# length = 10 -# breadth = 20 -# area = length* breadth -# print(area) -#variable -# num1 = 10 -# num2 = 23 -#data type -# int_var = 20 -# float_var = 345.45 -# bool_var = True -# str = "Python" -# print(int_var,type(int_var)) -# print(float_var,type(float_var)) -# print(bool_var,type(bool_var)) -# print(str,type(str)) -#multiple variable declaration -# a,b,c = "Asif",24,True -# print(id(a)) -# print(id(b)) -# print(id(c)) -# a=b=c=10 -# print(id(a),id(b),id(c)) -# x = 10 -# print(x,id(x)) -# x ="Afiya" -# print(x,id(x)) -# x = False -# print(x,id(x)) -#naming convention -# prod_id = 235335 -# cust_id = 33 -# first_name ="Md Asif" - -#python data types - numeric(int,float,boolean,complex) -# int_var = 234 -# float_var = 3453.564 -# bool_var = True -# complex_var = 2 + 3j -# print(int_var,type(int_var)) -# print(float_var,type(float_var)) -# print(bool_var,type(bool_var)) -# print(complex_var,type(complex_var)) -#sequence - list,tuple,string -# l = [23,11.22,True,"Asif"] -# for x in l: -# print(x) - -# print(l[0],l[1],l[2],l[3]) -# #list is mutable -# l[1]=200.40 -# l[3] = "Emon" -# print(l) -#tuple - immutable -# t = (12,22.334,False,"Python") -# for x in t: -# print(x) -# t[0]=10 -# print(t) -# str1 = 'Python' -# str2 = "Javascript" -# str3 = '''Golang''' -# print(str1,str2,str3) -# for x in str1: -# print(x) - -# print(str1[0],str1[1]) -# str[2]='j' - -# s ={12,34,"Asif",True} -# for x in s: -# print(x) - -# # print(s[0]) -# s[2]=12 -# str ="I love Python" - -# num1 = 2343242423422 -# print(type(num1)) -# num2 = 2342 -# print(sys.getsizeof(num1)) -# print(sys.getsizeof(num2)) -# float_val = 234.453590383030 -# print(sys.getsizeof(float_val)) -# bool_val = True -# print(sys.getsizeof(bool_val)) -# x = True -# y = False -# print(int(x),int(y)) -# print(type(x),type(y)) - -# complex_val = 2 + 3j -# print(complex_val) -# print(type(complex_val)) -# print(sys.getsizeof(complex_val)) -# c = complex(2,3) -# print(c) -# val = complex(23,34) -# print(val) -# var1 = complex(2,3) -# var2 = complex(3,4) -# print(var1+var2) -# a = 10 -# b = 20 -# c = a +b -# print(c) -#integer literal -# a = 10 -# b = 123_234_122 -# print(a,b) -# c = 12_22_10_234 -# # print(c) -# f = 123.4533 -# print(f) -# f1 = 22_2.22_42 -# print(f1) -# f2 = 23E2 -# print(f2) -# bool1 = True -# bool2 = False -# complex1 = 3 + 2j -# str1 = 'String1' -# str2 = "String2" -# str3 = '''String3''' -# txt1 = "Asif's age is 24" -# txt2 = 'quote"jneajgnaj"' -# print(txt1,txt2) diff --git a/section4.py b/section4.py deleted file mode 100644 index 949fd7d..0000000 --- a/section4.py +++ /dev/null @@ -1,23 +0,0 @@ -print("Operators and expressions") -#arithemtic(+,-,*,/,//,%,**) -# num1 = 123 -# num2 = 345 -# add = num1 + num2 -# sub = num1 - num2 -# multi = num1 * num2 -# div = num1 / num2 -# print(add,sub,multi,div) -# num1 = 455 -# num2 = 7 -# mod = num1%num2 -# print(mod) -# flo = num1 //num2 -# print(flo) -# x = 3 -# y = 4 -# z = 5 -# exp = x**y -# print(exp) -#precedence -(),**(r-l), /* // % ,+-(l-r) -# exp1 = 5 + 2*3 - 8/2 -# print(exp1) diff --git a/section5.py b/section5.py deleted file mode 100644 index 4e7c089..0000000 --- a/section5.py +++ /dev/null @@ -1,27 +0,0 @@ -print("Conditional Statements") -#relational operator - <,<=,>,>=,==,!= -# print(4>5) -# print(5<8) -# print(10==10) -# print(23!=22) -# age = 17 -# if age>=18: -# print("He can drive") -# else: -# print("He can't drive") -# num = int(input("Enter a number:")) -# if num>=0: -# print(num," is positive") -# else: -# print(num," is negative") - -# var1 = "Asif" -# var2 = False -# print(var1 or var2) -# a =8 -# print(not a) -# marks = 30 -# if marks>=45 and marks <=100: -# print("passed") -# else: -# print("failed") \ No newline at end of file diff --git a/sets.py b/sets.py new file mode 100644 index 0000000..77cd6bc --- /dev/null +++ b/sets.py @@ -0,0 +1,32 @@ +print("sets") +#s1 = {12,34,10,"Asif",True} +#print(s1) +# print(s1) +# s1 = set() +# print(s1) + +#creating sets +s1 = {} +# print(s1,type(s1)) +s1 = set() +#print(s1,type(s1)) +s2 = {12,3,23,12} +# print(s2) +#s3 = {1,2,3,4,{1,2}} +s4 = {12,3,"Asif",True,(1,2,3)} +print(s4) + +# s5 = set([2,3,4,4,6433,3,53535,3]) +# s6 = set("Asif") +# print(s5,s6) + +# s1 = {1,2,3} +# s2 = {3,2,1} +# print(s1==s2) + +#accessing items +s1 = {"Asif",24,True,23.99} +# print(s1[0]) +# print(s1[0:3]) +# s1[0] = 10 + diff --git a/store_sales.csv b/store_sales.csv new file mode 100644 index 0000000..0318ba6 --- /dev/null +++ b/store_sales.csv @@ -0,0 +1,101 @@ +order_id,customer_name,product,category,quantity,unit_price,total,order_date,country,payment_method +1,Tanvir,Jeans,Fashion,4,1500,6000,2025-01-18,Nepal,Card +2,Tanvir,Jeans,Fashion,5,1500,7500,2025-01-12,Pakistan,Card +3,Naila,Keyboard,Electronics,4,1200,4800,2025-01-22,Nepal,Card +4,Karim,Keyboard,Electronics,3,1200,3600,2025-01-23,Bangladesh,Card +5,Nahid,Keyboard,Electronics,1,1200,1200,2025-01-22,Nepal,Cash +6,Ayesha,Mobile,Electronics,1,25000,25000,2025-01-11,Nepal,Cash +7,Imran,Jeans,Fashion,1,1500,1500,2025-02-03,Nepal,UPI +8,Karim,Headphones,Electronics,2,3500,7000,2025-01-05,Pakistan,Card +9,Rahim,Headphones,Electronics,5,3500,17500,2025-01-01,India,UPI +10,Rafi,Headphones,Electronics,2,3500,7000,2025-01-11,Bangladesh,Card +11,Imran,T-Shirt,Fashion,2,500,1000,2025-01-26,Bangladesh,UPI +12,Imran,Jeans,Fashion,3,1500,4500,2025-01-11,Nepal,Cash +13,Asif,Headphones,Electronics,1,3500,3500,2025-01-05,Nepal,Card +14,Asif,Mouse,Electronics,5,600,3000,2025-01-01,Nepal,Card +15,Karim,Keyboard,Electronics,5,1200,6000,2025-01-14,Nepal,Card +16,Naila,Jeans,Fashion,3,1500,4500,2025-01-25,Pakistan,Cash +17,Rahim,Keyboard,Electronics,5,1200,6000,2025-01-23,Pakistan,UPI +18,Naila,Mouse,Electronics,4,600,2400,2025-01-21,Sri Lanka,UPI +19,Hasan,Headphones,Electronics,2,3500,7000,2025-01-31,Nepal,Card +20,Sadia,Shoes,Fashion,3,2000,6000,2025-01-13,Nepal,Card +21,Hasan,Mouse,Electronics,3,600,1800,2025-02-05,Bangladesh,Cash +22,Karim,Mouse,Electronics,3,600,1800,2025-01-24,Sri Lanka,Cash +23,Sadia,Shoes,Fashion,2,2000,4000,2025-02-02,Pakistan,Cash +24,Nahid,T-Shirt,Fashion,4,500,2000,2025-02-02,Bangladesh,Card +25,Imran,Mobile,Electronics,1,25000,25000,2025-01-23,Pakistan,UPI +26,Hasan,T-Shirt,Fashion,2,500,1000,2025-02-02,Bangladesh,UPI +27,Ayesha,Keyboard,Electronics,2,1200,2400,2025-01-15,Pakistan,Cash +28,Imran,Mouse,Electronics,2,600,1200,2025-01-18,Bangladesh,Cash +29,Hasan,Keyboard,Electronics,4,1200,4800,2025-01-04,Nepal,Cash +30,Naila,T-Shirt,Fashion,1,500,500,2025-02-03,Bangladesh,Cash +31,Naila,Shoes,Fashion,3,2000,6000,2025-01-10,Nepal,Card +32,Tanvir,Headphones,Electronics,5,3500,17500,2025-01-09,Bangladesh,Card +33,Nahid,Keyboard,Electronics,2,1200,2400,2025-01-03,Nepal,UPI +34,Sadia,Jeans,Fashion,3,1500,4500,2025-01-07,Sri Lanka,Card +35,Naila,Mouse,Electronics,3,600,1800,2025-01-08,Pakistan,Card +36,Karim,T-Shirt,Fashion,2,500,1000,2025-01-30,Bangladesh,Cash +37,Karim,Shoes,Fashion,5,2000,10000,2025-01-20,Nepal,UPI +38,Ayesha,Keyboard,Electronics,5,1200,6000,2025-02-03,Bangladesh,UPI +39,Rahim,T-Shirt,Fashion,1,500,500,2025-02-03,Nepal,Cash +40,Naila,Keyboard,Electronics,3,1200,3600,2025-01-13,India,Cash +41,Tanvir,Mobile,Electronics,1,25000,25000,2025-01-25,India,Card +42,Asif,Jeans,Fashion,1,1500,1500,2025-01-06,Nepal,Cash +43,Nahid,T-Shirt,Fashion,5,500,2500,2025-01-28,Bangladesh,UPI +44,Hasan,Mobile,Electronics,1,25000,25000,2025-01-28,Bangladesh,Cash +45,Asif,Mobile,Electronics,1,25000,25000,2025-01-16,Pakistan,Cash +46,Rafi,Mouse,Electronics,1,600,600,2025-01-04,Pakistan,UPI +47,Tanvir,Keyboard,Electronics,1,1200,1200,2025-01-24,Sri Lanka,UPI +48,Imran,Mouse,Electronics,3,600,1800,2025-01-09,Bangladesh,Card +49,Hasan,Keyboard,Electronics,1,1200,1200,2025-01-12,India,Cash +50,Hasan,Jeans,Fashion,2,1500,3000,2025-01-27,Pakistan,UPI +51,Rafi,Keyboard,Electronics,4,1200,4800,2025-01-31,Bangladesh,Cash +52,Ayesha,Shoes,Fashion,1,2000,2000,2025-01-28,Pakistan,Cash +53,Tanvir,Headphones,Electronics,4,3500,14000,2025-01-21,Bangladesh,Card +54,Asif,Shoes,Fashion,3,2000,6000,2025-01-13,India,Cash +55,Asif,Mouse,Electronics,5,600,3000,2025-01-10,Nepal,Cash +56,Hasan,Headphones,Electronics,5,3500,17500,2025-01-09,Pakistan,Cash +57,Nahid,Mouse,Electronics,2,600,1200,2025-01-15,Sri Lanka,Card +58,Karim,T-Shirt,Fashion,2,500,1000,2025-01-14,Pakistan,Cash +59,Asif,Mobile,Electronics,5,25000,125000,2025-01-30,Bangladesh,UPI +60,Imran,Shoes,Fashion,3,2000,6000,2025-01-07,Nepal,Cash +61,Sadia,Keyboard,Electronics,4,1200,4800,2025-01-14,Nepal,UPI +62,Nahid,Headphones,Electronics,3,3500,10500,2025-01-15,Sri Lanka,Card +63,Naila,Keyboard,Electronics,1,1200,1200,2025-01-01,India,UPI +64,Nahid,Mouse,Electronics,5,600,3000,2025-01-15,Sri Lanka,Cash +65,Hasan,Mouse,Electronics,1,600,600,2025-01-08,Bangladesh,Cash +66,Ayesha,Jeans,Fashion,2,1500,3000,2025-01-31,Nepal,Card +67,Sadia,Headphones,Electronics,2,3500,7000,2025-01-11,Sri Lanka,UPI +68,Karim,Mouse,Electronics,2,600,1200,2025-01-27,Sri Lanka,UPI +69,Sadia,Headphones,Electronics,4,3500,14000,2025-02-03,India,Cash +70,Imran,Jeans,Fashion,2,1500,3000,2025-02-05,India,Cash +71,Nahid,Mobile,Electronics,1,25000,25000,2025-01-08,Pakistan,Cash +72,Nahid,T-Shirt,Fashion,4,500,2000,2025-02-04,India,UPI +73,Rahim,T-Shirt,Fashion,1,500,500,2025-01-02,Nepal,UPI +74,Nahid,Keyboard,Electronics,5,1200,6000,2025-01-11,Nepal,Card +75,Hasan,Headphones,Electronics,5,3500,17500,2025-01-10,Bangladesh,Cash +76,Ayesha,Headphones,Electronics,4,3500,14000,2025-01-11,Pakistan,Cash +77,Ayesha,Mobile,Electronics,2,25000,50000,2025-02-03,India,Cash +78,Ayesha,Headphones,Electronics,4,3500,14000,2025-01-17,India,Card +79,Ayesha,Shoes,Fashion,1,2000,2000,2025-01-28,Bangladesh,UPI +80,Rahim,Mobile,Electronics,3,25000,75000,2025-01-23,Bangladesh,UPI +81,Tanvir,Shoes,Fashion,2,2000,4000,2025-01-17,India,Card +82,Naila,Mobile,Electronics,3,25000,75000,2025-01-22,Sri Lanka,Cash +83,Ayesha,Headphones,Electronics,4,3500,14000,2025-01-21,Pakistan,UPI +84,Naila,T-Shirt,Fashion,3,500,1500,2025-01-19,India,Card +85,Rafi,Jeans,Fashion,1,1500,1500,2025-01-18,Pakistan,Card +86,Karim,Keyboard,Electronics,3,1200,3600,2025-01-05,India,Cash +87,Rahim,Shoes,Fashion,1,2000,2000,2025-01-14,Nepal,Card +88,Ayesha,Headphones,Electronics,3,3500,10500,2025-01-12,Pakistan,Cash +89,Rafi,Mobile,Electronics,2,25000,50000,2025-01-14,Pakistan,Card +90,Naila,Jeans,Fashion,4,1500,6000,2025-01-03,Pakistan,Card +91,Hasan,Mouse,Electronics,2,600,1200,2025-01-15,Pakistan,Card +92,Asif,Mouse,Electronics,5,600,3000,2025-01-10,Pakistan,Cash +93,Nahid,T-Shirt,Fashion,5,500,2500,2025-01-26,Nepal,Cash +94,Nahid,Shoes,Fashion,2,2000,4000,2025-01-25,India,Card +95,Tanvir,Mobile,Electronics,4,25000,100000,2025-01-11,Sri Lanka,UPI +96,Nahid,Shoes,Fashion,2,2000,4000,2025-01-27,Pakistan,Cash +97,Tanvir,Shoes,Fashion,1,2000,2000,2025-01-05,Nepal,UPI +98,Asif,Mouse,Electronics,2,600,1200,2025-02-01,Nepal,Card +99,Ayesha,Headphones,Electronics,5,3500,17500,2025-01-22,Pakistan,Cash +100,Rahim,Jeans,Fashion,4,1500,6000,2025-01-09,Pakistan,UPI diff --git a/string.py b/string.py index 4da5536..6129aff 100644 --- a/string.py +++ b/string.py @@ -1,23 +1,340 @@ -print("String and String methods") -str1 = 'Hello Python' -str2 = "Hello Bangladesh" -str3 = '''Hello Bro''' -# print(str1,str2,str3) -# print(str1[0],str1[1],str1[2]) -# print(str2[-1],str2[-2],str2[-3]) -# for x in str1: -# print(x) -# for y in str2: -# print(y) -# for z in str3: -# print(z) -# print(len(str1),len(str2),len(str3)) - -# for i in range(len(str1)): -# print(str1[i]) +print("String and methods") + +# s1 = 'Hello Asif' +# s2 = "Hello Emon" +# s3 = """I am +# 24 years old""" + +# print(s1,s2,s3) +# s4 = str(2443.4) +# print(s4,type(s4)) + +# print("Hi i am 30 year's old") +# print('Hlw How are "you"') + +#accessing stings-indexing.slicing +s = "Hello Python" +# print(s[0]) +# print(s[6]) +# print(s[-1]) +# print(s[len(s)-6]) + +# print(s[15]) + +#slicing +# print(s[::]) +# print(s[::-1]) +# print(s[0:6:2]) +# print(s[1:5]) +# print(s[-1:-5:-1]) +# print(s[-1::]) +# print(s[-6:]) +# print(s[-5:-1]) + +#editing and deleting strings +# s[0] ="A" +# s1 = s[0] +# print(s1) +# s2 = s[1:4] +# print(s2) +# del s[0] +# del s[0:5] +# del s +# print(s) + +#operations on string +# print("Asif"+" "+"Arfi") +# print("Delhi"+ "Mumbai") +# print("Asif"*3) +# print("Asif"-23) +# print("*"*50) +# print("Asif">"Cinema") +# print("Emon">) + +#relational operator +# print("Asif"=="Asif") +# print(12 == 12.00) +# print("Dhaka"!="dhaka") +# print("Asif">"Asif") +# print("Asif"<"Emon") +# print('qwer'>="1234") + +# print("Asif" and "Afiya") +# print("" and "A") + +# print("Asif" or 12) +# print(False and "Asif") + +# print(not "") +# print(not "Asif") + +# for i in "Hello World": +# print(i) + +# s = "Asif is 24 years old" +# for i in range(0,len(s)): +# print(s[i]) + +#functions-len,min,max,sorted +s = "Hello Asif" +# print(len(s)) +# print(max(s)) +# print(min(s)) +# print(max('')) +# print(sorted(s,reverse=True)) + +#more functions - capitalize,title,upper,lower,swapcase +s = "hello WoRld" +# print(s.capitalize()) +# print(s.title()) +# print(s.upper()) +# print(s.lower()) +# print(s.swapcase()) + +#count/index/find +# print(s.count('o')) +# print(s.count('l')) +# # print(s.index("7")) +# print(s.find('w')) +# print(s.find('')) + +#find the length + +# s = input("Enter a string:") + +# count = 0 +# for i in s: +# count +=1 +# print(i) + +# print("length is:",count) + +# s = input('Enter email:') + +# username = "" +# for i in s: +# if i =="@": +# break +# else: +# username +=i + +# print("username:",username) + +# s = input("enter a string:") +# c = input("enter a character:") +# count =0 +# for x in s: +# if x == c: +# count +=1 + +# print(c," count:",count) + +# s = input("enter the string:") +# c = input("enter the character to remove:") + +# str1 = "" + +# for x in s: +# if x ==c: +# continue +# else: +# str1+=x + +# print("modified string:",str1) + + +#string revise +# s1 = 'Hello Asif' +# s2 = "Hello Python" +# s3 = """Hi +# i am asif""" +# print(s1,s2,s3) +# print("Hello I am 24 year's old") +# print('Hello "Probin ') +# s1 = str(2+3j) +# print(s1) + +#accessing string - index,slicing +s1 = "Hello Bangladesh" +# print(s1[0]) +# print(s1[-4]) +# print(s1[len(s1)-3]) +# print(s1[1:4]) +# print(s1[::-1]) +# print(s1[::]) +# print(s1[:4]) +# print(s1[-1:-5:-1]) + +#string is immutable - can't edit the string +s1 = "Hello Bangladesh" +# s1[0] = "As" +# print(s1) +# s1[1:3] = "Asif" +# print(s1[0]) +# del s1[0] +# del s1 +# print(s1) +#operations on string +#arithmetic - +/* +s1 = "Hello" +# print(s1*3) +# print(s1 + "Asif" + 23) +# print("Mumbai"+"Delhi") +# print("Asif"+"Asif") +#relational - <,<=,>=,>,==,!= +# print("Asif">"Himel") +# print("Asif"<"probin") +# print("Boss" == "Boss") +# print("Boss">"Asif") +# print("Asif"!="asif") +# print("Cat">"Catch") +# print("cat">"CAT") +#string formatting +# name = "Asif" +# age = 24 +# print(f"My name is {name} and age is {age}") +# str1 ="My name is {} and age is {}".format(name,age) +# print(str1) + +# print("Asif" and "Hasan" and "Probin") +# print("" and "Asif" and "9") +# print("Asif" or False) +# print("" or "AS") +# print(not "Asif") +# print(not "") +# for i in "Hello World": +# print(i) + +# for i in range(1,11): +# print(f"Hello World {i}") + +#membership operator - in,not in +# print("H" in "Hello") +# print("D" in "delhi") +# print("a" not in "Asif") + +#common function - len,max,min,sorted +s1 = "hello world" +# print(len(s1)) +# print(max(s1)) +# print(min(s1)) +# print(sorted(s1,reverse=True)) +# print(s1.capitalize()) +# print(s1.title()) +# print(s1.upper()) +# print(s1.lower()) +# print(s1.swapcase()) +# print(s1.count("o")) + +#find the length of a given string +# s = input("Enter a string:") +# counter = 0 +# for i in s: +# counter += 1 -# for i in range(len(str2)): -# print(str2[i]) +# print(f"length of string is : {counter}") -# for i in range(len(str3)): -# print(str3[i]) \ No newline at end of file +# email = input("Enter your email:") + +#string revise + +# str1 = 'Hello Asif' +# str2 = "Hello Python" +# str3 ="""Multiline +# string""" +# print(str1,str2,str3) +# print("Asif 's") +# print('Asif"ssf') +# str1 = str("Asif") +# print(str1) +s1 = "Hello Python" +# print(s1[4]) +# print(s1[-4]) +# print(s1[len(s1)-3]) +#slicing - [::] +# print(s1[1:5]) +# print(s1[::-1]) +# print(s1[::]) +# print(s1[:5]) +# print(s1[-3:-5:-1]) + +#s1[0] ="A" +# s2 = s1[0:4] +# print(s2) +# s = "Asif" +# # del s[0] +# del s +# print(s) +#operations on string +# print("Asif"+" "+"Asif") +# print("Asif"*3) +# print("Asif">="asif") +# print("Dhaka"<"Pune") +# print("cat">"catch") +#print("Asif"=="asifa") +# print("Asif"and"Asifa") +# print("sif"and"") +# print("" and "Asif") +# print("Asif"or"Shifa") +#print(not 23) +# s1 = "Hello Asif" +# for i in s1: +# print(i) +#print("D" in "Deshi") +# print(12 and 23 and 34) +# print(23 and "" and 34) +#common functions-min,max,len,sorted +# s1 = "Hello Asif" +# print(len(s1)) +# print(max(s1)) +# print(min(s1)) +# print(sorted(s1,reverse=True)) +# s1 = "hello World" +# print(s1.capitalize()) +# print(s1.upper()) +# print(s1.lower()) +# print(s1.title()) +# print(s1.swapcase()) +# s2 = "Hello Python" +# print(s2.swapcase()) +# print(s2.lower()) +# print(s2.upper()) +# print(s2.title()) +# print(s2.capitalize()) +#string formatting- format,f-string +# name = "Asif" +# age = 25 +# print("My name is {} and age is {}".format(name,age)) +# print(f"My name is {name} and age is {age}") +#functions to check if a string meets a criteria +# s = "HelloWorld" +# print(s.isalnum()) +# s = "!123Asif" +# print(s.isalnum()) + + + + + +# email = "haque.mdasif1501@gmail.com" +# username ="" +# for i in email: +# if i =='@': +# break +# else: +# username +=i +# print("Username :{}".format(username)) + +#count the frequency of a particular character in a string +# s = "hello how are you" +# char = 'h' +# count = 0 +# for i in s: +# if i == char: +# count +=1 + +# print(f"Frequency:{count}") + +#remove a particular character from a string +# s = input("Enter a string:") +# char = input("Enter a char:") diff --git a/strings.py b/strings.py new file mode 100644 index 0000000..796c146 --- /dev/null +++ b/strings.py @@ -0,0 +1,49 @@ +#creating string +# print('Hello World') +# print("Hello Python") +# print("""I am asif""") +# print("I am 24 year's old") +# print('I am " Asif') +# print("""Hello +# My name is +# Asif""") +# print(str(23)) +# li = str([12,3,2]) +# print(li,type(li)) + +#accessing the string - indexing/slicing +s1 = "Hello Bangladesh" +# print(s1[0]) +# print(s1[4]) +# print(s1[-2]) +# print(s1[len(s1)-5]) +# print(s1[::]) +# print(s1[::-1]) +# print(s1[2:6:2]) +# print(s1[:5]) +# print(s1[-1:-5:-1]) +# print(s1[-5:]) +# print(s1[-7:-3]) + +#edit and delete a string +#string is immutable , can't change particular value +s1 = "Hello Python" +# s1[0] ="A" +# print(s1) +# s2 = s1[:5] +# print(s2) +# s3 = s1[0] +# print(s3) +# del s1[0] +# del s1[:5] +# del s1 +# print(s1) + +#operation on string +# s1 = "Asif" +# s2 = "23" +# print(s1 + s2) +# print(s1 * 2) +# print("*" * 10) + +#relational operator diff --git a/tuples.py b/tuples.py new file mode 100644 index 0000000..ad2a9fd --- /dev/null +++ b/tuples.py @@ -0,0 +1,380 @@ +print("Tuples") +t1 =(12,11,22,11) +# print(t1[0]) +# print(t1[-1]) +# t1[3]=10 +#creating a tuple +# t1 =() +# print(t1) +# t2 =(1) +# print(t2,type(t2)) +# t3 = (1,) +# print(t3,type(t3)) +# t4 = (12,32,242,244) +# print(t4) +# t5 = ("Asif",24,True,[1,2,3]) +# print(t5) +# t6 = (1,2,3,4,(5,6,7)) +# print(t6) +# t7 = tuple("Asif") +# print(t7) +# t8 = tuple([1,2,3,5]) +# print(t8) + +#accessing tuples - indexing,slicing +t1 =("Asif",24,19.99,True,10,20) +# print(t1[0]) +# print(t1[-1]) +# print(t1[-3]) +# print(t1[::]) +# print(t1[1:3]) +# print(t1[::-1]) +# t1[6] ="A" + +#editing items +t1 = (12,3,4,2,23,22) +# t1[4] = 22 + +#adding r editing,deleting korte gele type error dekhai +#deleting items +# del t1[2] +# del t1 +# print(t1) +#operation on tuple +#arithmetic - + ,* +t1 = (1,2,3) +t2 = (1,2,3) +# print(t1+t2) +# print(t1*3) +#membership - in,not in +# print(1 in t1) +# print(10 not in t1) +# print(5 in t2) +# print(1 not in t2) +# print(t1 == t2) +# print(t1 is t2) +# for i in t1: +# print(i) + +# t1 = (1,2,3,(10,20),(30,40),(50,60)) +# for i in t1: +# if isinstance(i,tuple): +# for j in i: +# print(j) +# else: +# print(i) + +#tuple functions - max,min,len,sorted,sum +t1 =(1,2,3,4,5,6) +t2 =("Asif",24,True,19.99) +# print(max(t1)) +# print(max(t2)) +# print(min(t1)) +# print(min(t2)) +# print(len(t1)) +# print(len(t2)) +# print(sorted(t1,reverse=True)) +# print(sorted(t2)) +# print(sum(t1)) + + +#tuple revise +# tu = (12,34,22) +# tu[0] = 10 +# print(tu) +tu =("Asif",24,12,12) +# print(tu[0]) +# print(tu[1]) +# print(tu[2]) +# print(tu[3]) + +#creating a tuple +# t1 = () +# print(t1,type(t1)) +# t2 = ("Asif") +# print(t2,type(t2)) +# t3 = (23,) +# print(t3,type(t3)) + +# #homo +# t4 = (10,20,30,40) +# print(t4) +# #hetaro +# t5 = ("Asif",24,True,[1,2,3]) +# print(t5) +# #2D +# t6 = ("Asif",24,(1,2)) +# print(t6) +# #tuple constructor +# t7 = tuple("Asif") +# print(t7) +# t8 = tuple((10,20,30)) +# print(t8) + +#accessing items-indexing,slicing +t1 = ("Asif",24,True,[1,2,3]) +# print(t1[0]) +# print(t1[-1]) +# print(t1[len(t1)-3]) + +# print(t1[::]) +# print(t1[::-1]) +# print(t1[0:3]) +# print(t1[-4:]) +# print(t1[-5:-4:-1]) + +#editing items-cannot edit because tuple is immutable +# tu = (10,20,30,40) +# tu[0] = 100 +# print(tu) +#adding items is not possible +# tu = (1,2,3,4) +# tu[10]=10 + +#deleting items +# t = (10,20,30,40) +# del t +# print(t) + +#operations on tuple +t1 = (10,20,30) +t2 = (10,20,30) +# print(t1 + t2) +# # print(t1 * t2) +# print((10,20)* 5) +# print(t1 == t2) +# print(t1 == t2) +# print(5 in t1) +# print(10 in t1) +# print(5 not in t1) +# for i in t1: +# print(i) + +#tuple functions- max/sum/min/max/len/sorted +# t1 = (12,3,4,2,5) +# t2 = ("Asif","Probin","Emon") +# print(len(tu)) +# print(max(t1)) +# # print(max(t2)) +# print(min(t1)) +# # print(min(t2)) +# print(sum(t1)) +# # print(sum(t2)) +# print(sorted(t1,reverse=True)) +# print(sorted(t2)) + +# print(t1.count(2)) + +# t1 = (10,20,30,40,30) +# print(t1.count(30)) +# print(t1.index(50)) + +t1 = (10,20,("Asif","Probin"),(1,2,3),(20,30,40)) +# for i in t1: +# for j in t1: +# if isinstance(j,tuple): +# print(j) +# print(i) +# for item in t1: +# if isinstance(item,tuple): +# for j in item: +# print(j) +# else: +# print(item) +# t2 = ("Asif",(10,20),(1,2,3),[5,10,15]) +# for i in t2: +# if isinstance(i,tuple or list): +# for j in i: +# print(j) +# else: +# print(i) + +#list vs tuple +# import time + +# l = list(range(10000000)) +# t = tuple(range(1000000)) + +# start_time = time.time() + +# for i in l : +# a = i * 5 +# print("time taken for l:",time.time()-start_time) + +# start_time = time.time() +# for j in t: +# b = j * 5 +# print("time taken for t:",time.time()-start_time + +#memory +# import sys +# l = list(range(1000)) +# t = tuple(range(1000)) + +# print("Loop size:",sys.getsizeof(l)) +# print("Tuple size:",sys.getsizeof(t)) + +#tuple revise + +#special syntax - +# a,b,c = (10,20,30) +# # print(a,b,c) +# a,b = ("Asif",23,10) +# print(a,b) +# name,age,isStudent = ("Asif",25,True) +# print(isStudent) +# print(age) +# print(name) +# a = 1 +# b = 2 +# a,b = b,a +# print(a,b) + +#tuple tasks +# test_list = [(5,6),(5,7),(5,8),(6,10),(7,13)] +# new_list =[] +# for i in test_list: +# for j in test_list: +# if i[0] == j[0]: +# new_list.append() + +# t1 = (1,2,3,0) +# t2 = (0,1,2,3) + +# for i in t1: +# if t1[i] != t2[i]: + +# else: +# print(f"{t1} and {t2} are same") + +#question 4 + + +#tuple revise +t1 = (12,23,22,11,12) +# # print(t1) +# print(type(t1)) +# print(t1[0]) +# t2 = () +# print(t2) +# t3 = (23) +# print(t3,type(t3)) +# t4 =(12,) +# print(t4,type(t4)) +# t5 = ("Asif",24,True) +# print(t5) +# t6 = (12,3,42,("A","B")) +# print(t6) +# t7 = tuple("Asif") +# print(t7) + +#accessing a tuple +t1 = (10,20,"Asif",True,29.99) +# print(t1[3]) +# print(t1[-3]) +# print(t1[len(t1)-2]) + +# print(t1[1:4]) +# print(t1[::]) +# print(t1[::-1]) +# print(t1[:-4:-1]) +#t1[0] = 100 +# del t1[1] +# del t1 +# print(t1) + +#t1[5]=30 + +#operations on tuple +#rithmetic - +,* +# t1 = (12,2,23,21,"Asif") +# t2 =(10,20,39,True) +# print(t1+t2) + +# t1 =("Asif",24,True) +# print(t1*4) + +t1 = (10,20,30,40) +t2 = (10,20,30,40) +# print(t1 > t2) +# print(t1 == t2) +# print(t1 is t2) +# print(12 in t1) +# for i in t1: +# print(i) +# person = ("Asif",22,"Bangladesh") +# name,age,country = person +# print(f"Name:{name},Age:{age},Country:{country}") + +#tuple functions-len,max,min,sum,sorted +t1 = (10,20,30,40,50,10) +t2 = ("Asif",True,19.99) +# print(len(t1)) +# print(len(t2)) +# print(max(t1)) +# #print(max(t2)) +# print(min(t1)) +# print(sum(t1)) +# print(sum(t2)) +#print(sorted(t1)) +#print(sorted(t2,reverse=True)) + +# print(t1.count(10)) +#print(t1.count(100)) +# print(t1.index(100)) +numbers = (1,2,3,2,4,2,5) +# print(numbers.count(2)) +# count = 0 +# for i in numbers: +# if i == 2: +# count +=1 +# print(count) +# print(numbers.index(4)) +# index = -1 +# for i in numbers: +# if i != 4: +# index+=1 +# print(index) + +#tuple unpacking +# t1 = (10,20,30,40) +# name,age,num1,num2 = t1 +# print(name,age,num1,num2) +# a,c = (1,2,3) +# print(a,c) +# a = 20 +# b = 40 +# b,a = a,b +# print(a,b) +# t = (1,2,3,4,5) +# l +# t1 = tuple(l)= [] +# for i in t: +# l.append(i) +# l.append(10) +# print(l) +# print(t1) + +#tuple unpacking +# a,b,*others = (10,20,30,40,50) +# print(a,b,others) +# name,age,*country =("Asif",24,"Bangladesh","India","China") +# print(name,age,country) + +#zipping tuples +# t1 = (10,20,30,40,50) +# t2 = (100,200,300,99) +# print(tuple(zip(t1,t2))) + +#data = (1,2,(3,4),(5,6,7)) +# print(data[2][1]) +# print(data[3][2]) +# for i in data: +# if isinstance(i,tuple): +# for item in i: +# print(item) +# else: +# print(i) + +#find the second largest element +t = (10,5,20,8,15)