Click here to Skip to main content
15,880,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The question is in my book and when I tried to make it in python, the program is showing error.

What I have tried:

So this is the code I've made:
<pre lang="Python">

a=input("Enter the line: ")
W=''
s=a.split()
for i in s:
    q=len(i)
    for b in range(q-1,-1,-1):
        w=w+b+' '
print(w)
Posted
Updated 30-Dec-22 7:49am
Comments
Dave Kreskowiak 30-Dec-22 12:10pm    
Why is it every noob thinks the error message is not important to solving the problem?

Look at your code:
Python
<pre lang="Python">

a=input("Enter the line: ")
W=''                    # the variable is named W with a capital letter
s=a.split()
for i in s:
    q=len(i)
    for b in range(q-1,-1,-1):
        w=w+b+' '       # here you try to use a variable named w with a lower case letter
print(w)

The take home lesson is to use meaningful variable names, so mis-spellings are easier to spot.

You can now figure out what is wrong in your actual loop process.
 
Share this answer
 
v2
Comments
CPallini 30-Dec-22 16:26pm    
5.
To add to what Richard has - rightly - said, you should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900