diff --git a/classes/class1.py b/classes/class1.py index a504d9d..583194b 100644 --- a/classes/class1.py +++ b/classes/class1.py @@ -2,7 +2,7 @@ class student(): name = "rakesh" website ="binarynote.com" expertise ="PHP, CSS, HTML,JavaScript,JQuery,WordPress and Now Python Django" - + def showMessage(self): print("This is a demo message from class ") diff --git a/classes/class2.py b/classes/class2.py new file mode 100644 index 0000000..eedb656 --- /dev/null +++ b/classes/class2.py @@ -0,0 +1,22 @@ +class student(): + name = "rakesh" + website ="binarynote.com" + expertise ="PHP, CSS, HTML,JavaScript,JQuery,WordPress and Now Python Django" + + def setData(self,name,web,exp): + self.name = name + self.website = web + self.expertise = exp + + def showData(self): + print("Name : ",self.name) + print("website : ", self.website) + print("Expertise :", self.expertise,"\n") + +#object creation +s = student() +s.showData() + +# set new Data using another function +s.setData("Swarnima", 'swarnima.com','Python, Django, CSS, JavaScript') +s.showData() \ No newline at end of file diff --git a/classes/classConstructor.py b/classes/classConstructor.py new file mode 100644 index 0000000..e8e2997 --- /dev/null +++ b/classes/classConstructor.py @@ -0,0 +1,21 @@ +class student(): + name="" + website="" + expertise="" + + def __init__(self): + self.name ="swarnima" + self.website = "http://www.swarnima.com" + self.expertise ="Django Specialist" + + def showData(self): + print("Name : ",self.name) + print("website : ", self.website) + print("Expertise :", self.expertise,"\n") + +#object creation +# + +s1 = student() #calling constructor +s1.showData() + diff --git a/first3char.py b/first3char.py new file mode 100644 index 0000000..a396635 --- /dev/null +++ b/first3char.py @@ -0,0 +1,9 @@ +def front3(str): + str1 = str[:3]*3 + print(str1) + +front3('java') +front3('Chocolate') +front3('ab') +front3('a') +front3('') \ No newline at end of file diff --git a/functions/factorial.py b/functions/factorial.py new file mode 100644 index 0000000..2221b95 --- /dev/null +++ b/functions/factorial.py @@ -0,0 +1,9 @@ +def factorial(): + n = int(input("Enter any number ")) + fact = 1 + for i in range(1,n+1): + fact *= i + print("Factorial of ", n ," is :",fact) + +#function call +factorial() \ No newline at end of file diff --git a/functions/factorial_value.py b/functions/factorial_value.py new file mode 100644 index 0000000..8cfd218 --- /dev/null +++ b/functions/factorial_value.py @@ -0,0 +1,9 @@ +def factorial(n): + fact = 1 + for i in range(1,n+1): + fact *= i + print("Factorial of ", n ," is :",fact) + +#function call +n = int(input("Enter any number ")) +factorial(n) \ No newline at end of file diff --git a/functions/recursive_factorial.py b/functions/recursive_factorial.py new file mode 100644 index 0000000..6adec87 --- /dev/null +++ b/functions/recursive_factorial.py @@ -0,0 +1,10 @@ +def factorial(n): + if n==1: + return 1 + else: + return n*(factorial(n-1)) + +#function call +n = int(input("Enter any number ")) +result = factorial(n) +print("factorial of {} is {} ".format(n,result)) \ No newline at end of file diff --git a/string/string1.py b/string/string1.py new file mode 100644 index 0000000..fa9c8b2 --- /dev/null +++ b/string/string1.py @@ -0,0 +1,6 @@ +str = "This is me rakesh" +n = len(str) +print('Length of string is : ',n) +str = str + "Hello rakesh" +print(str) +print(str[0]) \ No newline at end of file diff --git a/sum_digit.py b/sum_digit.py index 98f83d1..19e6188 100644 --- a/sum_digit.py +++ b/sum_digit.py @@ -1,6 +1,6 @@ -a = int(input("Enter any number :") - -while a!=0: +a = int(input("Enter any number :")) +sum =0 +while (a!=0): rem = a%10 sum = sum + rem a = int(a / 10)