Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Session 5 - String Outputs with Answer.pptx
1. Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS) 1
2. Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print (Msg3)
Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS) 2
6. SMS='rEPorTmE'
l=len(SMS)
R=''
print('Orignal:',SMS)
N=2
for c in range (l):
if c%2==0:
R+=chr(ord(SMS[c])+N)
elif SMS[c].isupper()==True:
R+=SMS[c].lower()
else:
R+=chr(ord(SMS[c])-N)
print('Final: ',R) 6
Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS)
10. mystr= "sTUdeNT"
newstr = ""
count = 0
for i in mystr:
if count%2 != 0:
newstr = newstr + str(count)
else:
if i.islower():
newstr = newstr + i.upper()
else:
newstr = newstr + i
count += 1
newstr = newstr + mystr[:1]
print("The new string is:", newstr)
10
Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS)
11. Output
The new string is: Ss1sUs3sEs5sTs
11
Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS)
12. S= ['H', 'A','R', 'M', 'O', 'N', 'I', 'O', 'U', 'S']
Size=len(S)
print(' Original List= ', S)
for i in range ( 0, Size-1,2):
temp=S[i]
S[i] =S[i+1]
S[i+1]=temp
for j in range (1, Size, 2):
if S[i]>='M' and S[i]<='U':
S[i]='@';
print(' New List= ', S)
Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS) 12
13. Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS) 13
RoughWork
['A', 'H', 'M', 'R', 'N', 'O', 'O', 'I', 'S', 'U']
Output
Original List = ['H', 'A', 'R', 'M', 'O', 'N', 'I', 'O', 'U', 'S']
New List = ['A', 'H', 'M‘,’@’ ', 'N', ‘@', 'O', 'I', ‘S', ‘@']
14. s= 'a ProFile'
print('Orignal:',s)
l=len(s)
r=‘ '
for x in range (l):
if s[x].islower():
r+=s[x].upper()
elif s[x].isupper():
if (x%2!=0):
r+=s[x-1].lower()
else:
r+=chr(ord(s[x])-1)
else:
r+=s[x]
print('Final: ',r) 14
Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS)
15. Output
Orignal: a ProFile
Final: A OROoILE
Greenfields Public School, Class -XII, Subject : Computer Science (083)
Prepared By Suman Gupta ( PGT CS) 15