Skip to main content

Posts

Showing posts from January, 2023

Online libary in python

  class Libary :     def __init__ ( self , list , name ):         self . booklists = list         self . name = name         self . lendDict ={}     def displayBooks ( self ):         print ( f "we have following books in the libary: { self . name } " )         for book in self . booklists :             print ( book )     def lendbook ( self , user , book ):         if book not in self . lendDict . keys ():             self . lendDict . update ({ book : user })             print ( "Lender-Book database has been updated. you can take the book now" )         else :             print ( f "book is already being used by { self . lendDict [ book ] } " )     def addbook ( self , boo...

while loop in python

  i = int ( input ( "enter the number: " )) while ( i <= 3 ):     print ( i )     i = i + 1 print ( "execution finished" ) count = 5 while ( count > 0 ):     print ( count , end = " " ) #end for print in one line     count = count - 1     # after coming out of while loop else executed else :     print ( "excution done" )   i = int ( input ( "enter a number" )) while ( i > 40 ):     print ( "your numbers are" , i )     i = i - 1 print ( "done" )

snake, water,gun game python

  import random def check ( comp , user ):     if comp == user :         return 0     if ( comp == 0 and user == 1 ):         return - 1     if ( comp == 1 and user == 2 ):         return - 1     if ( comp == 2 and user == 0 ):         return - 1     return 1 comp =( random . randint ( 0 , 2 )) user = int ( input ( "0 for snake, 1 for water and 2 for gun" )) score = check ( comp , user ) print ( "your choice:" , user ) print ( "computer choice:" , comp ) if ( score == 0 ):       print ( "its a draw" ) elif ( score ==- 1 ):     print ( "you Lose" ) else :     print ( "you won" )