Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
def factorial(n):
	if n == 1:
		return 1
	else:
		return n*factorial(n-1)


sum1 = []
sum =0
t = int(input("number of test cases:"))
count = 0
lism =[]
for i in range(t):
	print("test case:",i)
	r = int(input("enter the number of elements:"))# here 
    while r > 0:
        i = input("enter the elements of the list:")
        lis += [i]# here
        r -= 1
        lism.append(lis)
    lis = []

for n in lism:
	e = 0
	m = len(n)
print(m)


What does this mean and how it can be corrected because I am tried it but this isn,t fixing. i searched on google too but didn't found a useful solution.Please help to correct my code and also tell about the error it is showing.

What I have tried:

File "C:/Users/cheta/PycharmProjects/myproject/venv/practice.py", line 16
while r>0:
^
IndentationError: unindent does not match any outer indentation level

This is the complete output
Posted
Updated 6-Jan-20 2:10am

Python uses indentation to define code blocks, you can indent code by any amount, but it must match exactly in order to be at the same level.
so this is fine:
Python
if a==b :
   if c==d :
      x()
   y()
z()
But this:
Python
if a==b :
   if c==d :
      x()
 y()
z()
Will give you an indentation error because the call to y is not "lined up" with either if so the system doesn't know what to do with it.

Now, your code looks fine, but ... tabs and spaces are likely to be the problem. Editors that use tabs indent to the same position, but if you mix spaces in as well then the compiler doesn't know how many spaces a tab is supposed to represent.

Check your editor: some allow "show marks" to indicate tabs differently from spaces, some allow you to replace tabs with spaces (I'd turn that one on if I was you).

This is just one of the reasons I don't use Python: it's not designed to produce good, reliable, maintainable code!
 
Share this answer
 
Comments
Member 14517556 16-Aug-19 1:57am    
Do you mean that I should either use tabs or space in a code and not both because this confuses the compiler.
OriginalGriff 16-Aug-19 2:08am    
It depends on the editor you use, and it's settings, but basically, yes. :laugh:
Member 14517556 16-Aug-19 2:00am    
I have learned python till functions and is quite good at writing codes in it. Can you recommend which language I should start next as I am also no that much satisfied by python. I have two options : C++ and Java
OriginalGriff 16-Aug-19 2:14am    
I'd suggest C# - it's powerful, and can be used to program desktop, web, and mobile apps (including Android and iPhone with Xamarin) which Java can't, and doesn't have the complexity of C++ (which often allows you to make too many mistakes). There's even a project in the wings to use it directly in the browser instead of Javascript, which will be a major plus!
Java is pretty much limited to just Android devices (although you can run it in Windows, you don't see it used that much in practice, partly because of the need to install the java runtime)
Quote:
Unindent does not match any outer indentation level. What does this mean

This means that you can't have a line indented tabs ans the next with spaces. tabs and spaces are not interchangeable.
Python
for i in range(t):
	print("test case:",i)                           # here is indented with tab
	r = int(input("enter the number of elements:")) # here is indented with tab
    while r > 0:                                    # here is indented with spaces

You need to make your mind, you indent either with tabs, either with spaces, but you don't mix.
 
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