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.
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
Turn the following code into a function. It finds the name in a string and prints it. Pass in the string and return the
-
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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!