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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 48 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply