Python Code Practice
Python Code Practice
# To check the num entered ends at 7 strating from 107 till 197
for i in range(107,200):
n = i%10
if n==7:
print(i)
numberlist=[5,7,6,8,9]
stringlist="red"
colors=["black","pink"]
for i in numberlist:
print(i)
for i in stringlist:
print(i)
for i in colors:-+
print(i)
# To check the num entered ends at 7 strrating from 107 till 197
for i in range(107,200,10):
print(i)
if marks>=90:
else:
numberlist=[5,7,6,8,9]
stringlist="red"
colors=["black","pink","blue","orange"]
for i in numberlist:
print(i)
for i in stringlist:
print(i)
for X in colors:
print (X)
if X== "pink":
break
# Linear search
arr=[34,65,78,90,20]
for i in range(0,5):
if arr[i] == item:
break
else:
print("not found")
#linear search
itemarray=[34,56,78,99,100]
if itemarray[i]==item:
print("item found")
break
else:
flag=False
itemarray=[34,56,78,99,100]
for i in range (len(itemarray)):
if itemarray[i]==item:
index=i
flag=True
if flag==True:
else:
n = len(arr)
swapped = False
for i in range(n-1):
for j in range(n-1):
temp=arr[j]
arr[j]=arr[j+1]
arr[j+1]=temp
else:
swapped=False
for i in range(len(arr)):
# %d . The %d operator is put where the integer is to be specified. where as % is used to concatenate
string
# By default, the print function ends with a newline.Passing the whitespace to the end parameter
(end=‘ ‘) indicates that the end character has to be identified by whitespace and not a newline.
mystring="HUMAIRA"
index=0
len_mystring=len(mystring)
for i in range(0,len_mystring):
mychar=mystring.lower()
mychar1=mystring[index]
print (mystring[index])
index=index+1
print (mychar)
import numpy as np
arr1 = np.array([[23,67],[78,92],[44,83]])
print(arr1)
result= arr1[2, 1]
print(result)
print(arr1[1])
arr2=[[23,45,34],[23,54,66]]
for i in arr2:
print(i)
----------------------------------------------------------------------------------------------------------------------------------------
import numpy as myArray
myArray1 = myArray.array([[27, 31, 17], [19, 67, 48],[36, 98, 29],[42, 22, 95],
[16, 35, 61], [89, 46, 47], [21, 71, 28], [16, 23, 13], [55, 11, 77]])
print(*myArray1)
myarray2=myArray1[1,2]
print(myarray2)
#--------------------------------------------------------------------
students=[]
students=[""for i in range(5)]
students[0]=60
students[1]=70
students[2]=80
students[3]=83
students[4]=90
print(students)
#-----------------------------------------------------------------------
myArray=[
["a","b"],
["c","d"]
print(myArray[0][0])
#prints a
myArray=[
[1,2,3],
[4,5,6],
[7,8,9]
print(myArray[0][0])
print(row)
#------------------------------------------------------------------------
# geeting input at run time an appending it in array
stname=array('i',[])
print("enter names")
for j in range(namescount):
# stname.append(int(input("Enter names")))
names=(int(input()))
stname.append(names)
for j in range(namescount):
print(stname[j])
#---------------------------------------------------
#------------------------------------------------------------------------
students1[0][0]=100
students1[0][1]=90
students1[0][2]=80
students1[1][0]=70
students1[1][1]=60
students1[1][2]=50
students1[2][0]=40
students1[2][1]=30
students1[2][2]=20
for i in range(3):
for j in range(3):
print(students1[i][j])
# print()
#-------------------------------------------------------------------------------
ARRAYS PAST PAPERS