Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Overall Trouble, No Built-in functions allowed

Initially, I was trying to find a way to compare "word" and "vowels" for "i" and take that same I and replace it with the index in vowels2 since they're the same length. Here is the assignment directions --1664899584836.png
Python:
#vowels = ("a",  "e", "i", "o", "u")
#vowels2 = ("á", "é", "í", "ó", "ú")

vowels = ("a", "á", "e", "é", "i", "í", "o", "ó", "u", "ú")

def convert():
    word = input("Please enter a word: ")
    word = list(word)
    for i in range(len(word)):
        if (word[i] == vowels):
            del word[0] # just using this to find if the statement is true


    word = ''.join(word)
    print(word)
#use dictionary maybe


if __name__ == '__main__':
    convert()




#You have to convert it to a list. To convert a string str into a list, use the command list(str).
# To convert it back into a string, use the command word = ''.join(ls).
#á, é, í, ó, and ú
 
As this is an assignment, I will not give the code but, I will give the steps I took

1. manually create dict using vowels as key and stressed vowels as value
2. get user input and create list
3. loop through list
4. compare letter to dict keys and get first vowel using a counter
5. update letter in list with dict value
6. print joined list

Python:
vowels = ("a",  "e", "i", "o", "u")
vowels2 = ("á", "é", "í", "ó", "ú")

# Convert both tuples to a dict
mydict = dict(zip(vowels, vowels2))

# Define a function
def convert():
    # Create empty list
    # Get user input and create a list of letters
 
    # Set a counting variable
    i = 0

    # Loop over user input and append to empty list
    # While looping compare letters to dict keys and append first occurrence of vowel using dict value
    # else append letter as is
    # print/return joined list
 
Last edited:
Okay so I've updated it but I've run into the error of not being able to join the list and how to insert the stressed vowel
Python:
vowels = ("a",  "e", "i", "o", "u")
vowels2 = ("á", "é", "í", "ó", "ú")

mydict = dict(zip(vowels, vowels2))

def convert():
    my_list = list(input("Please enter a word: "))
    j = 0
    for i, letter in enumerate(my_list):
        if letter in mydict and j == 0:
            my_list.remove(letter)
            my_list.insert(i, mydict)

    my_list = ''.join(my_list)
    print(my_list)
#use dictionary maybe


if __name__ == '__main__':
    convert()




#You have to convert it to a list. To convert a string str into a list, use the command list(str).
# To convert it back into a string, use the command word = ''.join(ls).
#á, é, í, ó, and ú
 
Updated with appending all the letter from my_list to new_list
Python:
vowels = ("a",  "e", "i", "o", "u")

vowels2 = ("á", "é", "í", "ó", "ú")



mydict = dict(zip(vowels, vowels2))

print(mydict)



def convert():

    new_list = list()

    my_list = list(input("Please enter a word: "))

    j = 0

    #for i, letter in enumerate(my_list):

        #if letter in mydict and j == 0:

            #my_list.append(letter)

            #my_list.insert()

    for j, letter in enumerate(my_list):

        new_list.append(letter)

        if letter in mydict:

            new_list.remove(letter)

      



    new_list = ''.join(new_list)

    print(new_list)

#use dictionary maybe





if __name__ == '__main__':

    convert()









#You have to convert it to a list. To convert a string str into a list, use the command list(str).

# To convert it back into a string, use the command word = ''.join(ls).

#á, é, í, ó, and ú
[/CODE]
 
I missed the part in the title about not using built-in so, I rewrote the code a little. I'm at work now so can't really help now. Zip and list are built-in
 
Last edited:
You have given a great effort so, I'm going to post the code I came up with for you to look over.

Python:
# Create a dict of vowels / vowels will be key and stressed vowels will be value
mydict = {
    'a': 'á',
    'e': 'é',
    'i': 'í',
    'o': 'ó',
    'u': 'ú'
}

def convert():
    # Get user input
    user_input = input('Please enter a word\n>> ')

    # Set a counter variable
    i = 0

    # Create empty list and append letters from user_input
    letters = []
    for letter in user_input:

        # Check if letter is in mydict keys
        if letter in mydict.keys() and i == 0:
            # Letter is in mydict so set letter/vowel to stressed vowel
            letter = mydict[letter]
            i += 1
        # Append letters to list
        letters.append(letter)

    # return joined list
    return ''.join(letters)



   

print(convert())

Output:
Code:
Please enter a word
>> bear
béar
 
Back
Top Bottom