Page 1 of 1

Turn the following code into a function. It finds the name in a string and prints it. Pass in the string and return the

Posted: Fri May 20, 2022 5:15 pm
by answerhappygod
Turn the following code into a function. It finds the name in a
string and prints it. Pass in the string and return the name if it
is found and “Unknown” if not. Be sure to call the function to test
it. Test it both when the name is there and when it isn’t.
Turn The Following Code Into A Function It Finds The Name In A String And Prints It Pass In The String And Return The 1
Turn The Following Code Into A Function It Finds The Name In A String And Prints It Pass In The String And Return The 1 (24.11 KiB) Viewed 50 times
code:
namePart = "name: Anu Gao"
posName = namePart.find("name:")
if (posName > -1):
name = namePart[posName+6:len(namePart)]
else:
name = "Unknown"
print(name)
Save & Run Load History i namePart = "name: Anu Gao" 2 posName = namePart.find("name:") 3 if (posName > -1): 4 name = namePart [posName+6:len(namePart)] 5 else: 6 name = "Unknown" 7 print(name) 8