There is no ideal number of credit cards you should have to build and maintain good credit. Using just one or two credit cards properly can help do the trick. And even if you use multiple credit cards, what affects your credit score in the long term is how good you are at managing your debt, for better or worse.
Data released by Experian suggests that Americans had an average of 3.84 credit cards in the third quarter of 2020. However, this does not imply you need that many cards to get a good credit score. Using even two can serve the purpose well. What you mainly need to account for when using your credit cards and the consequent effect on your credit score is your credit utilization ratio. However, maintaining zero balances on all your cards might not be in your best interest.