prog

program2


a=raw_input("Enter a name: ")
r=a[::-1]
print "The reverse is " ,a[::-1]
for i in range(len(a)):
print a[:-i]
for i in range(len(a)):
print a[-i:]
print "the second steps are" ,a[0:len(a):2]
print "the Third steps are" ,a[0:len(a):3]
if a==r:
print a, "Is polyndrome"
else:
print a, "Is not polyndrome"
i=0
while i<=len(a): q=a[i] print q i=i+1

program2


print "HAI THIS VIKRAMKUMAR"
print ""
print "This programm check is the given digits are in the ascending are not "
def is_sorted(l)
a=[]
for i in l:
a.append(int(i))
print a
c=0
for s in range(0,len(a)-1):
if a[s]

program2


import string
print "HAI THIS VIKRAMKUMAR"
print ""

def has_duplicates(l):
l=str(l)
a=[]
for i in l:
a.append(int(i))
print "you entered lis is" ,a
w=0
for i in range(w,len(a)):
b=i
for i in range(len(a)-1):
if a[i]==a[b]:
return True
w=w+1
return False
print has_duplicates(input("Enter a value: "))
##########30r
def ha_duplicates(t):
"""Returns True if any element appears more than once in (t),
False otherwise."""
s = t[:]
s.sort()
for i in range(len(s)-1):
if s[i] == s[i+1]:
return True
return False
print ha_duplicates(raw_input("Enter a number :"))

program2


import random
print "HAI THIS VIKRAMKUMAR"
print ""
def random_bdays(n):
t = []
for i in range(n):
bday = random.randint(1, 365)
t.append(bday)
return t
print random_bdays(364)
def duplicates(l):
s = l[:]
s.sort()
for i in range(len(s)-1):
if s[i] == s[i+1]:
return True
return False
def main(students,samples):
c=0
for i in range(samples):
r=random_bdays(students)
if duplicates(r):
c=c+1
return c
print main(input("Enter the number of students"),input("Enter the samples"))

program2


l=raw_input("Enter a number: ")
a=[]
for i in l:
a.append(int(i))
print "you entered lis is" ,a
w=0
for i in range(w,len(a)-1):
b=i
for i in range(len(a)-1):
if a[i]==a[b] and len(a)>2:
a.pop(b)
print a
w=w+1
print a
for i in range(len(a)):
for i in range(len(a)-1):
if a[i]==a[i+1]:
a.pop(a[i])
print a ,"is"

program2


import string
filename="vikram.txt"
file= open(filename,"w")
b=[]
a=[]
for i in range(input("How many wordsyou will enter: ")):
a=raw_input("Enter a line: ")
b.append(a)
for i in b:
file.writelines(i)
file.writelines(b)
file.close()
def make_word_list():
t = []
fin = open('vikram.txt')
for line in fin:
word = line.strip()
t.append(word)
print t
return t[0].count(raw_input("Enter a chr: "))
print make_word_list()

program2


def list():
file=open("words.txt")
li=[]
for i in file:
i=i.strip("\n")
li.append(i)
return li
def dict(b,word):
start=0
end=len(b)
while start<=end: f=(start+end)/2 k=b[f] if k==word: return f elif word>k:
start=f+1
elif word

program2


def list():
e=[]
file=open("words.txt","r")
for i in file:
i=i.strip("\n")
e.append(i)
return e
list=list()
def reverse_pairs(list):
c=[]
for i in range(len(list)-1):
a=list[i][::-1]
if a in list[i+1:]:
print [list[i],a]
c.append([list[i],a])
reverse_pairs(list)

program2


def list():
file=open("words.txt")
li=[]
for i in file:
i=i.strip("\n")
li.append(i)
return li
list=list()
l=[]
c=0
for i in range(len(list)-1):
string=list[i]
word1=list[i][0:len(string):2]
word2=list[i][1:len(string):2]
if word1 in list and word2 in list:
c=c+1
print [string,"===>", word1,word2]
if word1 in list and word2 in list:
l.append([string,[word1,word2]])
print c
print l

program2


import pygame
from pygame.locals import *
from sys import exit
from random import *
pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 32)
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
screen.lock()
for count in range(10):
random_color = (randint(0, 255), randint(0, 255), randint(0, 255))
random_pos = (randint(0, 639), randint(0, 479))
random_size = (639-randint(random_pos[0], 639), 479-randint(random_pos[1], 479))
pygame.draw.rect(screen, random_color, Rect(random_pos, random_size))
screen.unlock()
pygame.display.update()

program2


string1=raw_input("Enter first string: ")
string2=raw_input("Enter second string: ")
string=""
if len(string1)==len(string2):
for i in range(len(string1)):
string=string+string1[i]+string2[i]
print string
else:
print "wrong...........=-=-=-=-=-=-=_=_=_=_=-=-=-=-=-=-=-=-"

program2


import random
def randomdays(a):
l=[]
for i in range(a):
digit=random.randint(1,a)
l.append(digit)
print l
randomdays(input("Enter a number: "))
def has_duplicates(t):
s = t[:]
s.sort()
for i in range(len(s)-1):
if s[i] == s[i+1]:
return True
return False
c=0
for i in range(1000):
number=randomdays(23)
if has_duplicates(number):
c=c+1
print c

program2


print "HAI THIS VIKRAMKUMAR"
print ""
def remove_duplicate(n):
m=[]
a=[]
for j in str(n):
m.append(int(j))
if m[:]!=m[::-1]:
for i in m:
c=0
for x in m:
if x==i:
c=c+1
if c>=2:
m.remove(i)
print m

elif m[:]==m[::-1]:
a.append(m[1])
print a
n=input('Enter the numbers:')
remove_duplicate(n)

program2


"""

Solution to the word list exercise
Think Python
Allen B. Downey

"""

def make_word_list1():
t = []
fin = open('words.txt')
for line in fin:
word = line.strip()
t.append(word)
return t

def make_word_list2():
t = []
fin = open('words.txt')
for line in fin:
word = line.strip()
t = t + [word]
return t

t = make_word_list1()
print len(t)
print t[:10]

t = make_word_list2()
print len(t)
print t[:10]

program2


for i in range(1,123):
print "ord code is ", i , chr(i)
a=""
def rotate_word(s):
c=input("Enter a word: ")
for i in s:
b=ord(i)
if (b+c)<123 and (b+c)>=97:
print chr(b+c)
if (b+c)>123:
b=b-26
a=chr(b+c)
print a,
if (b+c)<97: b=b+26 print chr(b+c) rotate_word(raw_input("Enter a name : "))

program2


def find(str, ch):
for i in range(len(str)+1):
if str[i] == ch:
return i
str=raw_input("Enter a name: ")
ch=raw_input("Enter a charecter: ")
print find(str, ch)
a=[]
c=0
for i in str:
a.append(i)
b=a
for i in b:
if i==ch:
c=c+1
print "the count is" ,c

program2


s=str(raw_input("Enter the string: "))
n=int(raw_input("Enter the rotation value: "))
def rotate_word(string,no):
newstring=""
for i in string:
if((((ord(i))+no)<123) &((ord((i))+no)>=97)):
ascival=ord(i)+no
newstring=newstring+chr(ascival)
if ((ord(i)+no)>123):
ascival=ord(i)+no-26
newstring=newstring+chr(ascival)
if ((ord(i)+no)<96): ascival=ord(i)+no+26 newstring=newstring+chr(ascival) return newstring print rotate_word(s,n)

program2


def check(a):
for i in a:
if i.islower():
print i ,"is lower"
if i.isupper():
print i ,"is upper"
if i.isdigit():
print i ,"is digit"
check(raw_input("Enter a string : "))

new new new new dictionary


def rotate(word,number):
string=""
for i in word:
n=ord(i)+number
if n>64 and n<91: string=string+chr(n) elif n>96 and n<123: string=string+chr(n) elif n>122 or n>90:
n=n-26
string=string+chr(n)
return string
file=open("words.txt")
c={}
b=[]
a={}
n=input("Enter a number that you want to rotate: ")
for i in file:
i=i.strip("\n")
b.append(i)
c[rotate(i,n)]=i
for i in b:
if rotate(i,n) in b:
a[rotate(i,n)]=i
print a

program2


def rotate(word,number):
string=""
for i in word:
n=ord(i)+number
if n>64 and n<91: string=string+chr(n) elif n>96 and n<123: string=string+chr(n) elif n>122 or n>90:
n=n-26
string=string+chr(n)
return string
b={}
n=input("enter a number: ")
for j in open("words.txt"):
j=j.strip("\n")
b[j]=rotate(j,n)
print b

program2


def key(target):
a=[]
file=open("words.txt")
for i in file:
i=i.strip("\n")
a.append(i)
d=dict()
for j in a:
d[j]="vikram"
if target in d.keys():
print "your key is in the dictionary"
else:
print "sorry try again"
if raw_input("Are you want to sea the entire dict type y/n : ")=="y":
print d
key(raw_input("Enter a key: "))

ROT 13


def bisect(list1,number):
dictionary=0
last=len(list1)-1
while dictionary<=last: middle=(dictionary+last)/2 if number>list1[middle]:
dictionary=middle+1
elif number64 and n<91: if a>90:
a=a-26
string=string+chr(a)

string=string+chr(a)
elif n>96 and n<123: if a>122:
a=a-26
string=string+chr(a)
string=string+chr(a)
if bisect(s,string) and bisect(s,j):
dic[j]=string
print dic
def dict():
s=file_reading()
if raw_input("are you want to enter the number you want to rotate? (y/n): ") !="y":
for number in range(-26,26):
print "when iam rotate", number
dictionary(s,number)
print "when iam rotate 26 "
print "i will get entire dictionary"
else:
n=input("Enter a number that you want to rotate: ")
dictionary(s,n)
def rotate(word,number):
string=""
for i in word:
n=ord(i)+number
if n>64 and n<91: string=string+chr(n) elif n>96 and n<123: string=string+chr(n) elif n>122 or n>90:
n=n-26
string=string+chr(n)
return string
def asin():
file=open("words.txt")
c={}
b=[]
a={}
n=input("Enter a number that you want to rotate: ")
for i in file:
i=i.strip("\n")
b.append(i)
c[rotate(i,n)]=i
for i in b:
if rotate(i,n) in b:
a[rotate(i,n)]=i
print a
if raw_input("are you want to check the rotate pairs by in operator the enter in or are you want to check by bisect then enter bisect: Enter your chice: ") !="in":
print "this is by bisect: " ,dict()
else:
print "this is by in operator::: " ,asin()

program2


program2

No comments:

Post a Comment