You can also get a text message or phone call from Apple to get the verification code.
Follow the steps, mentioned in the related article:
...
If you don’t have a trusted device handy, you can have a verification code sent to your trusted phone number as a text message or phone call.
- Select “Didn’t Get a Code?” or “Can’t get to your devices?” on the verification code screen.
- Choose to have the code sent to your trusted phone number.
- You’ll get a text message or phone call from Apple with your verification code. If you use the Unknown Senders filtering in the Messages app, check there for your verification code.

4 .Enter the code on your other device to complete sign in.
...
copied from: Get a verification code and sign in with two-factor authentication - Apple Support
The Account Recovery process would be another option:
How to use account recovery when you can’t reset your Apple Account password - Apple Support