Like stated in the comments: put the relevant code in the try clause, and raise a specific exception. You can prompt again with a loop. Something like this:
succeeded = False
while not succeeded:
try:
aws_account = input("Enter the name of the AWS account you'll be working in: ")
session = boto3.Session(profile_name=aws_account)
client = session.client('iam')
succeeded = True
except botocore.ProfileNotFound:
print("No account exists by that name.")
2
solved Try except in Python, error still happens