Getting redundant code, is it normal?

Hi,
This is my first experiment with Codex, so , I wrote the given prompt, and got the following code in response. But I feel that the BOLD code is redundant, would you agree? Is this normal?
(davinci-codex)

‘’’
Program to input a string and find number of uppercase vowels, lowercase vowels, uppercase consonants, lowercase consonants , digits and special characters, and store in a dictionary.
‘’’

str1=input(“Enter a string:”)
d={‘uppercase vowels’:0,‘lowercase vowels’:0,‘uppercase consonents’:0,‘lowercase consonents’:0,‘digits’:0,‘special characters’:0}
for i in str1:
if i.isupper() and i in ‘AEIOU’:
d[‘uppercase vowels’]+=1
elif i.islower() and i in ‘aeiou’:
d[‘lowercase vowels’]+=1
elif i.isupper() and i in ‘BCDFGHJKLMNPQRSTVWXYZ’:
d[‘uppercase consonents’]+=1
elif i.islower() and i in ‘bcdfghjklmnpqrstvwxyz’:
d[‘lowercase consonents’]+=1
elif i.isdigit():
d[‘digits’]+=1
else:
d[‘special characters’]+=1
print(d)

2 Likes

Hello @Gaurav4, welcome to the OpenAI Community and excellent question!

You are correct. The bold text is redundant because once the character has been determined to not be a vowel, it can be assumed that if it returns True for i.isupper() or i.islower(), then it has to be a consonant since those functions can only return False for digits and special characters.

Good eye! You should try and practice improving your prompt and try to get the most optimized answer from Codex. It’s great practice for when you try and get Codex to do harder things! Make sure to hit the ‘Thumbs Up!’ if you do get the most optimized answer for that program and you’re on the Playground. It’ll help OpenAI Staff and Codex with better code completion in the future!

1 Like

Thanks for the help, I am just familiarizing myself with codex, it seems I need to better understand the settings of codex. It feels so exciting to be connected this project. When I received the email invite, it literally got me out of a low phase.

2 Likes

Hi, thanks for a prompt response. I actually gave a thumbs up even for the redundant code output! I was so excited even to get this output, It was magical. But yea, its probably a good idea to learn to give better prompt and tinker with the settings, and experiment with simpler programs which are easier to verify.
Btw, I just started learning coding this year, and python, 3 months back.

2 Likes