Posts

Showing posts from June, 2021

[2D ARRAY] Input from user in numpy Two Dimensional Array using for Loop in Python

Image
  from numpy import * # Taking input in 2D Array using numpy and for loop k= int ( input ( "Enter no of Rows \t " )) s= int ( input ( "Enter no of coloumn \t " )) ma=zeros((k , s) , dtype = int ) u= len (ma) print (u) print (ma) for i in range (u): for j in range ( len (ma[i])): p= int ( input ( 'Enter elements \t ' )) ma[i][j]=p print (ma)

[2D ARRAY ] Two Dimensional Numpy Array using array Function in Python

Image
  from numpy import * ks=array([[ 10 , 45 , 6 ] , [ 4 , 8 , 9 ]]) for r in ks: for c in r: print (c) print ()

[ARRAY] GETTING INPUT FROM USER IN NUMPY ONE DIMENSIONAL ARRAY USING FOR LOOP

  from numpy import * n= int ( input ( 'Enter elements: \t ' )) ks=zeros(n , dtype = int ) for i in range (n): p= int ( input ( 'Enter subjects marks \t ' )) ks[i]=p print (ks)

Array Methods

1. Insert Method from array import * ks=array( 'i' , [ 1 , 4 , 5 , 6 ]) for k in ks: print (k) print ( "after insert methode" ) ks.insert( 3 , 1025 ) #This is the insert method where 3 is index number and 1025 is # value that you want to insert for k in ks: print (k) 2.Pop Method from array import * ks=array( 'i' , [ 1 , 4 , 5 , 6 ]) for k in ks: print (k) print ( "after pop methode" ) ks.pop() # it will remove last element for k in ks: print (k)

[ARRAY] Getting input from user using for loop

Image
  # Getting input from user from array import * kartik = array( 'i' , []) sen= int ( input ( "please Enter how manay element that you want \n " )) for i in range (sen): kartik.append( int ( input ( "pls enter something \n " ))) for i in range ( len (kartik)): print (kartik(i))

Print array

Image
  from array import * ks=array( 'i' , [ 10 , 450 , 45 , 78 , 7777 , 752 ]) # ks[0]=455 # print(ks[0]) # for k in ks: # print(k) print ( len (ks)) for k in range ( 6 ): print (ks[k])

Snake water and Gun game

Image
import random # Snake Water Gun or Rock Paper Scissors def gameWin (comp , you): # If two values are equal, declare a tie! if comp == you: return None # Check for all possibilities when computer chose s elif comp == 's' : if you== 'w' : return False elif you== 'g' : return True # Check for all possibilities when computer chose w elif comp == 'w' : if you== 'g' : return False elif you== 's' : return True # Check for all possibilities when computer chose g elif comp == 'g' : if you== 's' : return False elif you== 'w' : return True print ( "Comp Turn: Snake(s) Water(w) or Gun(g)?" ) randNo = random.randint( 1 , 3 ) if randNo == 1 : comp = 's' elif randNo == 2 : comp = 'w' elif randNo == 3 : comp = 'g' you = ...

Multiplication table and I/O files

  # num=int(input("Enter a number that you want to print MULTIPLICATION table\n")) # for i in range(1,11): # print(f"{num} X {i} = {num*i}") for k in range ( 1 , 21 ): with open ( f"Multiplication table of { k } " , 'w' ) as i: for j in range ( 1 , 11 ): i.write( f' { k } X { j } = { k*j }\n ' )