- 3
Hello world. Can someone help me with module 5 program?
16 Answers
+ 3
Which exactly help do you need? Clarify task? Fix program? Other?
+ 2
ΘΟΔΩΡΗΣ ΦΕΡΕΝΤΙΝΟΣ
Loop over the lines of the file. For each line in the file get the first letter in the line
(As shown, something like line[0], where line is the loops variable name) and concatenate that with the length of the line excluding the trailing whitespace newline character '\n' if present. (The last line of the file doesn't have a newline character). You can use the .strip() method on the line to remove the newline character if present and then get the len() of the line and concatenate it to the first letter then output it.
+ 1
ΘΟΔΩΡΗΣ ΦΕΡΕΝΤΙΝΟΣ, use `s[0]` to take the first character from the string `s`. That is what you want?
+ 1
ΘΟΔΩΡΗΣ ΦΕΡΕΝΤΙΝΟΣ, each user has their own code for Practice, Project and Code Coach tasks. 🤦
We can see it if you copy your code, paste it in Code Playground, save it and give us the link.
+ 1
ΘΟΔΩΡΗΣ ΦΕΡΕΝΤΙΝΟΣ, on SoloLearn, those tasks were especially made for people to solve it individually... 🤦🤦🤦
We in Discuss tab can only clarify task or fix the code...
+ 1
ChaoticDawg thank u
+ 1
file = open("/usercode/files/books.txt", "w")
file.write("Harry potter \n"
"The Hunger Games\n"
"Pride And Prejudice\n"
"Gone With The Wind \n")
file.close()
file = open("/usercode/files/books.txt", "r")
try:
for i in file:
counter=0
print(i[0]+str((len(i)-1)))
counter+=1
finally:
file.close()
Got output:
H12
T16
P19
G18
if someone missingT15 instead of T16 .....
don't worry...by putting some space or removing some space....
you need to get output...thats the question....
0
Hi! what exactly can't you do?
0
Ярослав Вернигора(Yaroslav Vernigora) i don't know how to take kai first letter. Maybe with list[0]?
0
do you want to take the first letter of a word separately?
0
Ярослав Вернигора(Yaroslav Vernigora) u can see the module 5 code
0
a task called book titles?
0
get You have been asked to make a special book categorization program, which assigns each book a special code based on its title.
The code is equal to the first letter of the book, followed by the number of characters in the title.
For example, for the book "Harry Potter", the code would be: H12, as it contains 12 characters (including the space).
You are provided a books.txt file, which includes the book titles, each one written on a separate line.
Read the title one by one and output the code for each book on a separate line.
For example, if the books.txt file contains:
Some book
Another book
Your program should output:
S9
A12
0
he needs a little push. Unfortunately, I haven't solved this problem myself yet. Until I got to her
- 1
get i can't do it