Posts

Showing posts from May, 2021

Animated btn

animated Animation Buttons Hover us and enjoy the satisfying neumorphic animation designs! Read More Read More Read More Read More Read More Read More Read More Read More Read More Read More Read More Click! Read More Read More Read More Read More Read More DEERBUCKS.DESIGNING

Python course

free course site Python link Wordpress

factorial_recursive

''' Created on May 29, 2021 @author: Admin ''' # n! = n * n-1 * n-2 * n-3.......1 # n! = n * (n-1)! def factorial_iterative(n): # """ # :param n: Integer # :return: n * n-1 * n-2 * n-3.......1 # """ fac = 1 for i in range(n): fac = fac * (i+1) return fac # def factorial_recursive(n): # """ # :param n: Integer # :return: n * n-1 * n-2 * n-3.......1 # """ # if n ==1: # return 1 # else: # return n * factorial_recursive(n-1) # 5 * factorial_recursive(4) # 5 * 4 * factorial_recursive(3) # 5 * 4 * 3 * factorial_recursive(2) # 5 * 4 * 3 * 2 * factorial_recursive(1) # 5 * 4 * 3 * 2 * 1 = 120 # 0 1 1 2 3 5 8 13 # def fibonacci(n): # if n==1: # return 0 # elif n==2: # return 1 # else: # return fibonacci(n-1)+ fibonacci(n-2) n = int(input("Enter then number...

Nested fun in py

x = "awesome" def myfunc(): global x x = "fantastic" myfunc() print("Python is " + x) ''' Created on May 29, 2021 @author: Admin ''' # l = 10 # Global # # def function1(n): # # l = 5 #Local # m = 8 #Local # global l # l = l + 45 # print(l, m) # print(n, "I have printed") # # function1("This is me") # # print(m) x = 89 def harry(): x = 20 def rohan(): global x x = 87 print("before calling rohan()", x) rohan() print("after calling rohan()", x) harry() # rohan() print(x)

Global Fun in py

''' Created on May 29, 2021 @author: Admin ''' # local variable example # def sum(): # # a=10 #local variable cannot be accessed outside the function # b=20 # sum=a+b # print( sum) # print(a) #this gives an error # sum() #global variable example a=1 def print_Number(): # a=a+1; // cannot edit global variable global a a=5 a=a+1; print(a) print_Number() print(a) #example 2 x = "awesome" def myfunc(): x = "fantastic" print("Python is " + x) myfunc() print("Python is " + x)

Demo health care

def take(k): #1st number code if k==1: print("-----------------------------------") print ("You entered in Aman Health care \n") print("-----------------------------------") c=int(input("enter 1 for ex 2 for health:")) if c==1: print("***********************************") print("you entered in excersice part") print("***********************************") elif c==2: print("***********************************") print ("\nYou entered in Aman health care ") print("***********************************") print("\n\t*****Thanks for visit us*****") #2nd elif k==2: print("-----------------------------------") print ("You entered in Preet Health care \n") print("-----------------------------------") c=int(input("enter 1 for ex 2 for health:")) if c==1: print("***************************...

Seek tell in py

''' Created on May 27, 2021 @author: Admin ''' f=open('test.txt') # where is pointer print(f.tell()) print(f.readline()) print(f.tell()) print(f.readline()) # if i use seek 0 then reading from starting f.seek(0) print(f.readline()) f.close() def square(n): '''Takes in a number n, returns the square of n''' return n**2 print(square.__doc__)

Star print

Parameter Values Parameter Description start Optional. An integer number specifying at which position to start. Default is 0 stop Required. An integer number specifying at which position to stop (not included). step Optional. An integer number specifying the incrementation. Default is 1 My other blog for More about ''' Created on May 26, 2021 @author: Admin ''' print("enter number:") n =int(input()) print("type 1 or 0:") one=int(input()) new=bool(one) if new ==True: for x in range(1,n,+1): # print(x) # print("bahar wala ",x) for i in range(1,x+1): #j bahar wale ki value lai raha hai print(i,end=" ") #useke according print kar raha hai # print("*", end=" ") # print("*",end=" ") print() elif new == False: for x in range(n,0,-1): # print(x) # print("bahar...

Write apend

''' Created on May 26, 2021 @author: Admin ''' # f =open("tst.txt",'w') # f.write("Aman is a good boy now im learning python ") # f =open("tst.txt",'a') # f.write("Aman is a good boy now im learning python \n ") # # f=open("tst.txt","rt") # # for c in f: # print(c) f=open("test.txt","r+") print(f.read()) f.write("\n You are great ") print(f.read()) f.close()

Read file

''' Created on May 26, 2021 @author: Admin ''' from gevent.tests.test__backdoor import readline print("file operation 1:\n") f =open('test.txt','rt') cont= f.read() print(cont) # for line in f: # print(line,end="") # print(f.readline()) # print(f.readline()) # print(f.readlines()) f.close()

File handling in py

''' Created on May 26, 2021 @author: Admin ''' ''' File Handling The key function for working with files in Python is the open() function. The open() function takes two parameters; filename, and mode. There are four different methods (modes) for opening a file: "r" - Read - Default value. Opens a file for reading, error if the file does not exist "a" - Append - Opens a file for appending, creates the file if it does not exist "w" - Write - Opens a file for writing, creates the file if it does not exist "x" - Create - Creates the specified file, returns an error if the file exists In addition you can specify if the file should be handled as binary or text mode "t" - Text - Default value. Text mode "b" - Binary - Binary mode (e.g. images) '''

Using Function Calc

/ New Blog def addition(num1,num2): print("Addition=",num1+num2) def subtraction(num1,num2): print("Subtraction=",num1-num2) def multiplication(num1,num2): print("Multiplication=",num1*num2) def division(num1,num2): print("Division=",num1/num2) while True: print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") print("5. Exit") choice=int(input("Enter your choice(1-5):")) if choice==1: num1=int(input("Enter 1st Number:")) num2=int(input("Enter 2nd Number:")) addition(num1,num2) elif choice==2: num1=int(input("Enter 1st Number:")) num2=int(input("Enter 2nd Number:")) subtraction(num1,num2) elif choice==3: num1=int(input("Enter 1st Number:")) num2=int(input("Enter 2...

Calc Add subtract multiplication and division KC

''' Created on May 25, 2021 @author: Admin ''' print("Enter Operator:") a=input() while True: if a == "+" : print("your wana add:") print("num 1:") a=int(input()) print("num 2:") b=int(input()) if a == 45 and b == 4: print("Ans is : ",a,"+",b,"=", 50) print("enter value for continue") else: print("Ans is:",a+b) if "yes"==input("if you wana continue type: \'yes\' "): print("Enter Operator:") a=input() else: print("\tThank you ...!") print("\t\tTry again..!") break elif a == "-": print("your wana subtact:") a=int(input("num 1:")) ...

Try catch

''' Created on May 23, 2021 @author: Admin ''' num1=input("enter 1st no") num2=input("enter 2nd no") try: num3=int(num1)+int(num2) print("Result is :",num3) except Exception as e: print(e) print("An exception occurred")

Function in py

''' Created on May 23, 2021 @author: Admin ''' # print("inbuilt function ") # print("hello ") # a=int(input("enter 1st number:")) # b=int(input("enter 2nd number:")) # c=sum((a, b)) # print(f"Sum is printed:{c} \n") #User define Function def Func1(): print("This is a function 1") # Func1() # Argument function # def fun2(a,b): # print("Sum is :",end=" ",a+b) # # fun2(44,66) # # # Return type function # # def fun3(a,b): # print("Returned :",end=" ") # # return a+b # # c=fun3(8, 5) # # print(c) def my_function(name,email_id): print(name,email_id) my_function("John","John@helix.co.in") my_function("Roshan","Roshan@helix.co.in") my_function("Prince","prince@helix.co.in") # Arbitrary Arguments, *args # def my_function(*kids): # print("The ...

Membership Operators

''' Created on Apr 21, 2021 @author: hp ''' print("Python Membership Operators") print("Membership operators are used to test if a \nsequence is presented in an object:") ''' in Returns True if a sequence with the specified value is present in the object x in y not in Returns True if a sequence with the specified value is not present in the object x not in y ''' print("\nif value is present in the object") list=[1,2,3,4,5] x=3 print("Result is :",x in list) print("\nif value is not present in the object") print(x not in list)

Logical Op

''' Created on Apr 21, 2021 @author: hp ''' from pickle import FALSE, TRUE from xml.sax import _false print("*** Logical Operators***") " Logical operators are used to combine conditional statements:" ''' Operator and Returns True if both statements are true or Returns True if one of the statements is true not Reverse the result, returns False if the result is true ''' x=False y=True print("result is :",x and y) print("\n and Operator :") x=10 y=10 A=2 B=3 print("if value",x, "or",y,"both true :",x==y and A==B) print("\n or Operator :") x=10 y=10 A=2 B=3 print("if value",x,y,"or ",A,B,"one is true :",x==y or A==B) print("\n Not Operator:") x=True y=True print("Retrun reverse result :",not x)

Identity Operators

''' Created on Apr 21, 2021 @author: hp ''' from pickle import TRUE print("Python Identity Operators") print("\nIdentity operators are used to compare the objects, not if they are equal,\n but if they are actually the same object, with the same memory location:") ''' Operator Description Example is Returns True if both variables are the same object x is y is not Returns True if both variables are not the same object x is not y ''' print("\nis operator:") x=True y=True print("Result is", x is y) print("\nis not Operator ") print("Result of is not :", x is not y)

Comparison Operators

''' Created on Apr 21, 2021 @author: hp ''' print("****Comparison Operators****") ''' Operator Name Example == Equal x == y != Not equal x != y > Greater than x > y = Greater than or equal to x >= y :") x=10 y=12 print("If value ",x, "is grater than ", y ,"result is ",x!=y) print("\n4th Less than =:") x=24 y=20 print("if value",x,"is Greater than or equal to ",y,"result is :",x>=y) print("\n6th Less than or equal to

Assignment Operators

''' Created on Apr 21, 2021 Python Assignment Operators Operator Example Same As = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 //= x //= 3 x = x // 3 **= x **= 3 x = x ** 3 &= x &= 3 x = x & 3 |= x |= 3 x = x | 3 ^= x ^= 3 x = x ^ 3 >>= x >>= 3 x = x >> 3

Airthmetic Operator my code

''' Created on Apr 21, 2021 Operators are= Arithmetic operators Assignment operators Assignment_2 operators Logical operators Identity operators Membership operators Bitwise operators @author: hp ''' '''Arithmetic operators + Addition =x + y - Subtraction =x - y * Multiplication =x * y / Division =x / y % Modulus =x % y ** Exponentiation =x ** y // Floor division =x // y ''' print(" + Addition") x=9 c=10 a=x+c print (x, "or" , c) print("Result is :",a) print(" - subtraction") x=9 c=10 a=x-c print (x, "or" , c) print("Result is :",a) print("* Multiplication") x=9 c=10 a=x*c print (x, "or" , c) print("Result is :",a) print("/ Division") x=9 c=10 a=x/c print (x, "or" , c) print("Result is :",a) print("% Modulus")...

Shorthand code rule

''' Created on May 21, 2021 @author: Admin ''' # If-expression if(Condition) else else-expression # if condition: # if-expression # else: # else-expression c = int(input("enter 1:")) print(" c is",c ) d = int(input("enter 2:")) print("D is ",d ) # shorthand print("C grater") if c>d else print(" D grater")

Python Operators

''' Created on May 21, 2021 @author: Admin ''' # Operators In Pythons # Arithmetic Operators # Assignment Operators # Comparison Operators # Logical Operators # Identity Operators # Membership Operators # Bitwise Operators # Arithmetic Operators # print("5 + 6 is ", 5+6) # print("5 - 6 is ", 5-6) # print("5 * 6 is ", 5*6) # print("5 / 6 is ", 5/6) # print("5 ** 3 is ", 5**3) # print("5 % 5 is ", 5%5) # print("15 // 6 is ", 15//6) # Assignment Operators # print("Assignment Operators") # x = 5 # print(x) # x %=7 # x = x%7 # print(x) # Comparison Operators i = 5 # Logical Operators a = True b = False # Identity Operators # print(5 is not 5) # Membership Operators list = [3, 3,2, 2,39, 33, 35,32] # print(324 not in list) # Bitwise Operators # 0 - 00 # 1 - 01 # 2 - 10 # 3 - 11 print(0 & 2) print(0 | 3)

Game code when over

''' Created on May 21, 2021 @author: Admin ''' n=18 no_of_guess=1 print("Number of guesses is limited") while no_of_guess 18: print("please enter less number\n") else: print("you won \n") print(no_of_guess,"no.of guesses he took to finish.") break print(9-no_of_guess,"no. of guesses left") no_of_guess = no_of_guess + 1 if(no_of_guess>9): print("Game Over") break

faulty ‍ Calc using pythoon

print("Enter Operator:") a=input() if a == "+" : print("your wana add:") print("num 1:") a=int(input()) print("num 2:") b=int(input()) if a == 45 and b == 4: print("Ans is : ",a,"+",b,"=", 50) print("enter value for continue") else: print("Ans is:",a+b) print("for Continue enter operator:") a=input("Enter Operator:") if a == "-": print("your wana subtact:") a=int(input("num 1:")) b=int(input("num 2:")) if a == 15 and b == 4: print("Ans is :",10) else: print("Ans is:",a-b) print("for Continue enter operator:") a=input("Enter Operator:") if a == "*": print("your wana Multiplication:") a=int(input("Enter num 1:")) b=int(input("Enter num 2:")) if a ...

Auto comment in eclips IDE with pc name & date of code

''' Created on May 20, 2021 @author: Admin ''' print("Shift + Alt + J for add auto comment ")

Break and continue

''' Created on May 20, 2021 @author: Admin ''' # print("while loop:") # i=0 # while (True): # if i+1 100: print("Congrats you entered grater then 100\n") else: print("wrong input\n")

Game code

''' Created on May 21, 2021 @author: Admin ''' i=0 while i 9: print(f"You entered {guess}") print("please enter {less} num.\n") elif guess 8: print(f"you lost {i} change ") print("Game is over \n \t \t Try Again ") break print(9-i,"left chance") ''' uess=18 count=1 while(True): user=int(input("Enter the guessing number: ")) if user==guess: print(f"you won!!! you guess in {count} times") break else: print(f"wrong guess!!! you guess {count} times") count = count + 1 if count==9: break '''

While loop

''' Created on May 20, 2021 @author: Admin ''' print("while loop:") i=0 while (i

For loop in py

# list1=[1,2,3,4,5] # # print(list1[0]) # for item in list1: # print(item) # list1 = [ ["Harry", 1], ["Larry", 2], # ["Carry", 6], ["Marie", 250]] # dict1 = dict(list1) # for item in dict1: # print(item) # for item, lollypop in dict1.items(): # print(item, "and lolly is ", lollypop) items = [int, float, "amanY", 5,3, 3, 22, 21, 64, 23, 233, 23, 6] for item in items: if str(item).isnumeric() and item>=6 and item

Example 2

a=input("Enter Operator:") if a == "+": print("your wana add:") a=int(input("num 1:")) b=int(input("num 2:")) if a == 45 and b == 4: print("Ans is :",50) else: print("Ans is:",a+b) if a == "-": print("your wana subtact:") a=int(input("num 1:")) b=int(input("num 2:")) if a == 15 and b == 4: print("Ans is :",10) else: print("Ans is:",a-b) if a == "*": print("your wana Multiplication:") a=int(input("Enter num 1:")) b=int(input("Enter num 2:")) if a == 19 and b == 4: print("Ans is :",23) else: print("Ans is:",a*b) if a == "/": print("your wana Division:") a=int(input("Enter num 1:")) b=int(input("Enter num 2:")) if a == 100 an...

If else in python

# from typing import List # var1=4 # var2=57 # var3=int(input("enter value:")) # if var3>var2: # print("grater") # elif var3==var2: # print("equal") # else: # print("lesser ") # list1=[1,2,3,4,5] # if 4 in list1: # print("yes in the list") # if 16 not in list1: # print("Not in list ") # my excersice age= int(input("enter age :")) if age >18: print("you can drive ") elif age==18: print("we will decide ") else: print("you can't drive ")

SET in python

s={1,0,1,2,2,3,4,3,2} print(type(s)) print(sorted(s)) print(sorted(s,reverse=True)) # s = set() # # print(type(s)) # # l = [1, 2, 3, 4] # # s_from_list = set(l) # # print(s_from_list) # # print(type(s_from_list)) # s.add(1) # s.add(2) # s.remove(2) # s1 = {4, 6} # print(s.isdisjoint(s1))

Management code in python

class hotelfarecal: def __init__(self,rt='',s=0,p=0,r=0,t=0,a=1800,name='',address='',cindate='',coutdate='',rno=101): print ("\n\n*****WELCOME TO OUR HOTEL*****\n") self.rt=rt self.r=r self.t=t self.p=p self.s=s self.a=a self.name=name self.address=address self.cindate=cindate self.coutdate=coutdate self.rno=rno def inputdata(self): self.name=input("\nEnter your name:") self.address=input("\nEnter your address:") self.cindate=input("\nEnter your check in date:") self.coutdate=input("\nEnter your checkout date:") print("Your room no.:",self.rno,"\n") def roomrent(self):#sel1353 print ("We have the following rooms for you:-") print ("1. type A---->rs 6000 PN\-") prin...

Example Dic

dic={1:"one", 2:"two", 3:"three", 4:"four"} # print(dic["2"]) a=int(input("Enter value:")) if a in dic: print(dic[a]) # print(dic) else: print("Sorry...! you entered wrong input\n Bcoz You cross the") print("If you want to update this type below \n") hi=input("enter yes :") if "yes" in hi: b=int(input("Updateing key number:")) c=input("Updateing key number:") dic.update({b:c}) print(dic) print("Thanks for using it ") else: print(hi * 2,"\nwrong input\n may be spell mistake") # else: # a=int(a) # for x in range(0,a): # print(x)

List tupple dic set

aman={"fist":"Aman", "Mid":"preet", "last":"singh"} # print("This is a dict") # print(type(aman),"\n") # preet=[1,2,3,4,5] # print("This is a list") # print(type(preet),"\n") # singh=(1,2,3,4,5) # print(" This is a tuple") # hello={1,2,3,4,5,7} # print(" This is a set") # print(type(hello),"\n") # print(type(singh),"\n") # var=input("enter value:") # car=input("enter value:") # swaping var,car=car,var a,b,c="1","2","3" # aman.update({"salman":var,"bhadla":car}) print(aman.values()) # for x in aman.items(): # print(x) print(a,b,c) # print(type(singh)) # for x in aman.keys(): # print(x)

Dictionary in python

# dic={"1":"one", "2":"two" } # print(dic) a = {'key': 'value', 'cow':'mooh'} print(a['cow']) #will print "mooh" on the screen # Dictionary is nothing but key value pairs d1 = {} # print(type(d1)) d2 = {"Harry":"Burger", "Rohan":"Fish", "SkillF":"Roti", "Shubham":{"B":"maggie", "L":"roti", "D":"Chicken"}} # d2["Ankit"] = "Junk Food" # d2[420] = "Kebabs" # print(d2) # del d2[420] # print(d2["Shubham"]) # d3 = d2.copy() # del d3["Harry"] # d2.update({"Leena":"Toffee"}) # print(d2.keys()) # print(d2.items())f i=0 while i

List in python

list1 = ['harry', 'ram', 'Aakash', 'shyam', 5, 4.85] # Lists in Python [] # list with no member, empty list [1, 2, 3] # list of integers [1, 2.5, 3.7, 9] # list of numbers (integers and floating point) ['a', 'b', 'c'] # lisst of characters ['a', 1, 'b', 3.5, 'zero'] # list of mixed value types ['One', 'Two', 'Three'] # list of strings # List Methods : l1=[1,8,4,3,15,20,25,89,65] #l1 is a list print(l1) l1.sort() print(l1) #l1 after sorting l1.reverse() print(l1) #l1 after reversing all elements # List Methods :- list1=[1,2,3,6,4,5,4] #list1 is a list list1.append(7) # This will add 7 in the last of list list1.insert(3,8) # This will add 8 at 3 index in list li...

String in python

# String Functions: demo = "Aman is a good boy" print(demo.endswith("boy")) print(demo.count('o')) print(demo.capitalize()) print(demo.upper()) print(demo.lower()) print(demo.find("is")) print(demo.replace("good","nice")) # print(demo) # print("aman") print("Half printed =>",demo[0:5]) mystr = "Harry is a good boy" # print(len(mystr)) # print(mystr[::-2]) print(mystr.endswith("bdoy")) print(mystr.count("o")) print(mystr.capitalize()) print(mystr.replace("is", "are")) #9 #9 #9

Variables in python

Variable in python print("\n\n") # Variable in Python: # abc = "It's a string variable" # abcnum = 40 # It is an example of int variable # abc123 = 55.854 # It is an example of float variable # print(abcnum + abc123) # This will give sum of 40 + 55.854 # print(type(abc)) # print(abc) # num1=23 # num2=55 # print(int(num1)+int(num2)) ''' quiz1 : # ''' # AB= input("Enter number :") # print(AB) print("calculator") x=input("enter num1:") x=int(x) y=input("enter num2:") y=int(y) z=x+y print("Answer is :", z)

Comments in python

Comments in python import os #hary 7 print(os.listdir(), "\n\n") '''This is a comment Author: AMAN Date: 27 November 2020 Multi-line comment ends here ''' print("Main code started") #Now I will write my code here: # print statement for printing strings print("AMAN is a programmer", end=" ") # Print statement with a literal print("sum is ", end=" ") print(1+87) #This will print "AMAN is a programmer**88" on the screen #Please dont remove this line """ This is a Multiline Comment """ """ This is a comment """ # print("Subscribe CodeWithAMAN now","Bhai video bhi like kar dena") # print("next line") # print("C:\'narry") print("AMAN is \n good boy \t1") #comment after statement # Escape Sequences Description # \n Inserts a new line in the text at the point # \\ In...

Hello print in python

Python hello world code: ''' Created on 16-May-2021 @author: dell ''' # thisis a comment print("Hello ") """This is a comment in multiline """