The document contains multiple Python functions that manipulate strings in various ways, including changing case, counting upper and lower case letters, replacing vowels, and modifying characters based on conditions. Each function is demonstrated with a call that shows its output. The document also includes examples of using lists and tuples with loops to perform calculations and modifications.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views
OUTPUT WITHOUT ANSWER
The document contains multiple Python functions that manipulate strings in various ways, including changing case, counting upper and lower case letters, replacing vowels, and modifying characters based on conditions. Each function is demonstrated with a call that shows its output. The document also includes examples of using lists and tuples with loops to perform calculations and modifications.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
Find and write the output of the following Python codes:
def makenew(mystr): s="welcome2kv"
newstr = " " n = len(s) count = 0 m="" for i in mystr: for i in range(0, n): if count%2 !=0: if (s[i] >= 'a' and s[i] <= 'm'): newstr = newstr+str(count) m = m +s[i].upper() else: elif (s[i] >= 'n' and s[i] <= 'z'): if i.islower(): m = m +s[i-1] newstr = newstr+i.upper() elif (s[i].isupper()): else: m = m + s[i].lower() newstr = newstr+i else: count +=1 m = m +'#' newstr = newstr+mystr[:1] print(m) print("The new string is :", newstr)
#function calling makenew("sTUdeNT")
def display(s): def change(s):
l = len(s) d = {"UPPER" : 0, "LOWER" : 0 } m="" for c in s: for i in range(0,l): if c.isupper(): if s[i].isupper(): d["UPPER"] += 1 m=m+s[i].lower() elif c.islower(): elif s[i].isalpha(): d["LOWER"] += 1 m=m+s[i].upper() else: elif s[i].isdigit(): pass m=m+"$" print("Upper case count :", d["UPPER"]) else: print("Lower case count :", d["LOWER"]) m=m+"*" print(m) #function calling change("School Days are Happy") display("EXAM20@cbse.com")
def Convert(Old): def Show(str):
l=len(Old) m="" New=”” for i in range(0,len(str)): for i in range(0,1): if(str[i].isupper()): if Old[i].isupper(): m=m+str[i].lower() New=New+Old[i].lower() elif str[i].islower(): elif Old[i].islower(): m=m+str[i].upper() New=New+Old[i].upper() else: if i%2==0: elif Old[i].isdigit(): m=m+str[i-1] New=New+”*” else: else: m=m+"#" New=New+”%” print(m) return New Show('HappyBirthday') Older = “InDIa@2020” Newer=Convert(Older) print(“New string is: “,Newer)
def replaceV(st): def swap(P ,Q):
newstr = '' “ P,Q=Q,P for character in st: print( P,"#",Q) if character in 'aeiouAEIOU': return (P) newstr += '*' else: R=100 newstr += character S=200 return newstr R=swap(R,S) print(R,"#",S) st = “Hello how are you” st1 = replaceV(st) print("The original String is:", st) print("The modified String is:", st1)
def Display(str): Text="Welcome Python"
m="" L=len(Text) for i in range(0,len(str)): ntext="" if(str[i].isupper()): for i in range (0,L): m=m+str[i].lower() if Text[i].isupper(): elif str[i].islower(): ntext=ntext+Text[i].lower() m=m+str[i].upper() elif Text[i].isalpha(): else: ntext=ntext+Text[i].upper() if i%2==0: else: m=m+str[i-1] ntext=ntext+"!!" else: print (ntext) m=m+"#" print(m)
Display('Fun@Python3.0')
def mainu(): s=”United Nations”
Moves=[11, 22, 33, 44] for i in range(len(s)): Queen=Moves if i%2==0: Moves[2]+=22 print(s[i],end= ‘ ‘) L=len(Moves) elif s[i]>=’a’ and s[i]<=’z’: for i in range (L): print(‘*’, end= ‘ ‘) print(Queen[L-i-1], "#", Moves [i]) elif s[i]>=’A’ and s[i] <=’Z’: print(s[i:],end= ‘ ‘) #function calling mainu() tup=(10,30,15,9) L =["X",20,"Y",10,"Z",30] s=1 CNT = 0 t=0 ST = "" for i in range(s,4): INC = 0 t=t+tup[i] for C in range(1,6,2): print(i,":",t) CNT= CNT + C t=t+tup[0]*10 ST= ST + L[C-1] + "@" print(t) INC = INC + L[C] print(CNT, INC, ST)
def increment(n): def display(x=2,y=3):
n.append([4]) x=x+y return n y += 2 print(x,y) L=[1,2,3] display() M=increment(L) display(5,1) print(L, M) display(9)
newstr = " " for i in range(len(data)-1): count = 0 if(data[i].isupper()): for i in mystr: data[i]=data[i].lower() if count%2 !=0: elif(data[i].isspace()): newstr = newstr+str(count) data[i]=data[i+1] else: print (data) if islower(i): newstr = newstr+upper(i) else: newstr = newstr+i count +=1 newstr = newstr+mystr[:1] print ("The new string is :",newstr)