s=input("enter string ") print("the string in reverse") l=len(s) for a in range(-1 ,(-l-1),-1): print(s[a],end=' ')
Program Execution:
enter string navodaya the string in reverse a y a d o v a ns=input("enter string ") l=len(s) i=0 for a in range(-1 ,(-l-1),-1): print(s[i],"\t",s[a]) i+=1
output:
enter string school s l c o h o o h o c l s'a' in 'heya'
True'jap' in 'japan'
In [1]:
name='superb'
for ch in name:
print(ch,'-',end='')
In [3]:
s=input("enter string ")
print("the string in reverse")
l=len(s)
for a in range(-1 ,(-l-1),-1):
print(s[a],end=' ')
In [4]:
s=input("enter string ")
l=len(s)
i=0
for a in range(-1 ,(-l-1),-1):
print(s[i],"\t",s[a])
i+=1
In [2]:
'a' in 'heya'
Out[2]:
In [3]:
'jap' in 'japan'
Out[3]:
In [6]:
'paj' not in 'japan'
Out[6]:
In [4]:
ord('a')
Out[4]:
In [5]:
ord('A')
Out[5]:
In [6]:
ord('1')
Out[6]:
In [12]:
word='amazing'
In [7]:
chr(65)
Out[7]:
In [13]:
word
Out[13]:
In [15]:
word[-5:-1]
Out[15]:
In [16]:
word[0:-1]
Out[16]:
In [15]:
w="india"
w[0:]
Out[15]:
In [17]:
word[0:]
Out[17]:
In [20]:
word[-len(word):5]
Out[20]:
In [21]:
len(word)
Out[21]:
In [17]:
Out[17]:
In [24]:
word[0]
Out[24]:
In [25]:
word[-1]
Out[25]:
In [26]:
s1='spam'
s2='ni'
print("hello,"+s2)
print(3*s1+2*s2)
print(s1[1])
In [18]:
s=input("enter string")
l=len(s)
c=0
for i in range(l):
if s[i]in'aeiou':
c+=1
print("number of vowelis ",c)
In [25]:
s="india is my country"
t=s.split()
print(s)
print(t)
print(len(s),len(t))
In [29]:
'apple'>'pineapple'
Out[29]:
In [30]:
'ab'>'XY'
Out[30]:
In [31]:
'Ax'>'aX'
Out[31]:
In [33]:
'apple'in 'pineapple'
Out[33]:
In [34]:
'pine' in 'Pineapple'
Out[34]:
In [35]:
s='apple'
In [37]:
s[:-1]+s[-1:]
Out[37]:
In [38]:
s='#'
p=''
for a in range(5):
p+=s
print(p)
In [40]:
n=int(input('enter number'))
s='*'*n
for i in range(n):
print(s)
s=s[:-1]
In [41]:
sr='kundeshwar'
sr.capitalize()
Out[41]:
In [43]:
sr.find('d')
Out[43]:
In [45]:
sr='--===='
sr.isalnum()
Out[45]:
In [46]:
sr.isalpha()
Out[46]:
In [48]:
sr.isdigit()
Out[48]:
In [49]:
sr.isspace()
Out[49]:
In [50]:
sr.isupper()
Out[50]:
In [51]:
sr.islower()
Out[51]:
In [52]:
sr='hello'
print(sr.lower())
print(sr.upper())
In [ ]:
line=input("enter line")
x=line.split()
y=''
for i in range(len(x)):
x[i]=x[i].upper()
y+=x[i]
print(y)
In [ ]:
In [3]:
line=input("enter line")
x=line.split()
y=''
for i in range(len(x)):
x[i]=x[i].upper()
y+=' '+x[i]
print(y)
In [ ]:
s=input("enter phone number with in format stdcode-areacode-number stdcode of 3 digit area code of three digit ad number of 4 digit")
if s[0:4].isdigit():
print("areacode is right")
In [ ]:
#programt to enter a phone number with 10 digit and two dashes with dashes after area code and next three numbers
#for example 017-555-1212 is valid
s=input("enter phone number with in format stdcode-areacode-number stdcode of 3 digit area code of three digit ad number of 4 digit")
if s[0:4].isdigit():
print("areacode is right")s=input("enter phone number with in format stdcode-areacode-number stdcode of 3 digit area code of three digit ad number of 4 digit")
if len(s)==12 and s[0:3].isdigit() and s[4:7].isdigit() and s[8:].isdigit()and s[3]=='-'and s[7]=='-' :
print('string is ok')
else:
print('incorrect string')
In [ ]:
#program to enter a string extract all digit from string ,sum all digit in string
#print origianl string ,the digit ,the sum of digit
#if no digit print 'has no digit'
#if input is 'abc123' than output willbe
#print abc123 has the digits 123 which sum to 6
str=input('enter string')
sum=0
dstr=''
for i in range(len(str)):
if str[i].isdigit():
sum+=int(str[i])
dstr+=str[i]
print(str,'has the digits',dstr,'which sum is',sum)
In [ ]:
#program to enter a string extract all digit from string ,sum all digit in string
#print origianl string ,the digit ,the sum of digit
#if no digit print 'has no digit'
#if input is 'abc123' than output willbe
#print abc123 has the digits 123 which sum to 6
str=input('enter string')
sum=0
dstr=''
for i in range(len(str)):
if str[i].isdigit():
sum+=int(str[i])
dstr+=str[i]
print(str,'has the digits',dstr,'which sum is',sum)
In [2]:
#9c3 program to enter a string and print number of word ,character in string
s=input('enter string')
sp=s.split()
cw=len(sp)
cch=len(s)
an=0
print(s,'has number of word',cw,'and number of character',cch)
for i in range(len(s)):
if s[i].isalnum():
an+=1
print('number of alphanumeric is ',an,'and its percentage is',(an/cch)*100)
In [ ]:
#9c5 input one integer and one string ,collect digit sequence from string
#then sum digit sequence and integer
n=int(input('enter number'))
s=input('enter a string')
sd=''
for i in range(len(s)):
if s[i].isnumeric():
sd+=s[i]
print('the sum is ',n+int(sd))
In [ ]:
#9c6 write program to input two string and print small string first then
#print large string in format ex input string is panda python then output will be
#panda
#p n
# y o
# th
s=input('enter first string')
s1=input('enter second string')
ls=len(s)
ls1=len(s1)
if(ls>ls1):
s,s1=s1,s
ls,ls1=ls1,ls
print(s)
for i in range(int(ls1/2)+1):
print(' '*i,s1[i],' '*(ls1-1-2*i),s1[ls1-1-i])
No comments:
Post a Comment