Yasha Syed295
Badges: 0
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 5 years ago
#1
Can someone help me with this code i am doing my GCSE computing CA A453 and am stuck on this task. i am able to print the sentence and also print the index numbers. but i cant continue the program further. The question is as follows

Develop a program that identifies individual words in a sentence, stores these in a list and replaces
each word in the original sentence with the position of that word in the list.
For example, the sentence
ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR
COUNTRY
contains the words ASK, NOT, WHAT, YOUR, COUNTRY, CAN, DO, FOR, YOU
The sentence can be recreated from the positions of these words in this list using the sequence
1,2,3,4,5,6,7,8,9,1,3,9,6,7,8,4,5
Save the list of words and the positions of these words in the sentence as separate files or as a single
file.
Analyse the requirements for this system and design, develop, test and evaluate a program to:
• identify the individual words in a sentence and store them in a list
• create a list of positions for words in that list
• save these lists as a single file or as separate files.
Please help me
0
reply
username2471155
Badges: 20
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#2
Report 5 years ago
#2
UWS might be able to help.
0
reply
UWS
Badges: 21
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#3
Report 5 years ago
#3
(Original post by Illimitable)
UWS might be able to help.


Would love to help but as Ascel says... OP hardly has given enough information to assess the situation. It's just "help me".
0
reply
username2471155
Badges: 20
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#4
Report 5 years ago
#4
(Original post by UWS)
Would love to help but as Ascel says... OP hardly has given enough information to assess the situation. It's just "help me".
True, as soon as I saw Computing you were the first person who came to mind.
0
reply
Yasha Syed295
Badges: 0
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#5
Report Thread starter 5 years ago
#5
sentence = input("Enter a sentence: ")
sentence = sentence.lower().split() words = []
for word in sentence:
if word not in words: words.append(word)
positions = [words.index(word) for word in sentence]
print("The positions of the words are",positions)
position = input("Please enter a position : ")
recreated = " ".join([words[i] for i in position]) print(recreated)
This is my code currently
This prints the sentence and also the index numbers but it doesn't regenerate the sentence after the user had entered the positions
0
reply
Yasha Syed295
Badges: 0
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#6
Report Thread starter 5 years ago
#6
the language i am using is Python
0
reply
banf
Badges: 2
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#7
Report 5 years ago
#7
(Original post by Yasha Syed295)
sentence = input("Enter a sentence: "
sentence = sentence.lower().split() words = []
for word in sentence:
if word not in words: words.append(word)
positions = [words.index(word) for word in sentence]
print("The positions of the words are",positions)
position = input("Please enter a position : "
recreated = " ".join([words[i] for i in position]) print(recreated)
This is my code currently
This prints the sentence and also the index numbers but it doesn't regenerate the sentence after the user had entered the positions
Hi, have you managed to do this, I am currently in the same position as you and am not sure how to go about this?! I need to recreate the sentences from the text file.
0
reply
Yasha Syed295
Badges: 0
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#8
Report Thread starter 4 years ago
#8
i have tried some but i need to check again and i think for regenerating the sentence, u need to use functions
0
reply
username2980692
Badges: 9
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#9
Report 4 years ago
#9
(Original post by Yasha Syed295)
i have tried some but i need to check again and i think for regenerating the sentence, u need to use functions
This is Task 1... if you are still on Task 1 in February then you are truly screwed...
0
reply
niteninja1
Badges: 22
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#10
Report 4 years ago
#10
I must admit even at degree level I couldn't do this in python but that's because I'm a prolog and java programmer
0
reply
_Thomas
Badges: 7
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#11
Report 4 years ago
#11
(Original post by Kronixion)
This is Task 1... if you are still on Task 1 in February then you are truly screwed...
99% sure this is task 2. Task 1 was identifying the index positions of a given word within a sentence?

OP, this isn't that difficult. I think I even found the whole code you need on StackOverflow - go look on there
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Have you ever considered or are you currently considering an apprenticeship?

Yes, I am actively considering an apprenticeship (58)
12.53%
I am actively considering an alternative to uni that isn't an apprenticeship (8)
1.73%
I have considered an apprenticeship but it's not for me (122)
26.35%
I am considering a degree apprenticeship (43)
9.29%
I haven't considered an apprenticeship (217)
46.87%
Something else (let us know in the thread!) (15)
3.24%

Watched Threads

View All