Turn on thread page Beta
    • Thread Starter
    Offline

    14
    ReputationRep:
    Hi so I've been trying to get this code to work but its not doing what I want it to. I have defined the function main() which analyses an inputted sentence and finds out positions of words. Then the user is asked if they want to input more sentences. I want the whole process to repeat if they say 'Yes' but its not working. here's my code:
    def main():

    sentence = input("Input a sentence: ")

    print(sentence)
    spl = sentence.split()
    print(spl)

    dictionary = dict((sentence, spl.index(sentence)+1) for sentence in set(spl))

    print(dictionary)

    sentence_Positons = list(map(lambda sentence: dictionary[sentence], spl))
    print(sentence_Positons)


    inv_dictionary = {v: k for k, v in dictionary.items()}
    print(inv_dictionary)
    file = open("Task3.txt","w")

    file.write(str(sentence_Positons ))
    file.close()
    file = open("Task3.txt","r")

    fileSENTENCE_Positons = file.readline()

    print("From file: ",fileSENTENCE_Positons)

    file.close()

    print("This is the sentence decompressed from the txt file:")
    print(list(map(lambda sentence: inv_dictionary[sentence], sentence_Positons)))

    main()

    user = input('Any more?')


    while user == 'Yes' and not 'No':
    main()
    user = input ('Any more?')




    Any help or advice would be greatly appreciated thanks xx
    Offline

    7
    ReputationRep:
    It seems unnecessary to specify 'and not no' as if this were true then the first condition wouldn't be true, making having both redundant.
    However, I doubt that is causing the issue. It may be something to do with the function identifier main() being reserved? (I'm not sure on this, i've never tried calling a function main)
    • Thread Starter
    Offline

    14
    ReputationRep:
    (Original post by indiamai)
    It seems unnecessary to specify 'and not no' as if this were true then the first condition wouldn't be true, making having both redundant.
    However, I doubt that is causing the issue. It may be something to do with the function identifier main() being reserved? (I'm not sure on this, i've never tried calling a function main)
    OMG I acc tried that and it works Thankyou soooo much x
    Can't believe I didn't think of that :/
    Offline

    7
    ReputationRep:
    (Original post by DD2508)
    OMG I acc tried that and it works Thankyou soooo much x
    Can't believe I didn't think of that :/
    No problem!
 
 
 
Poll
Do you want your parents to be with you when you collect your A-level results?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.