I keep getting an indentation error when submitting my programing homework in mimir.ide enter image description here
Here is my code:
number = input("Please enter a phone number:")
characters = number.split('-')
AC = characters[0]
NC = characters[1:]
value =''
for n in NC:
for i in range (len(n)):
if n[i] in 'ABC':
value = value '2'
elif n[i] in 'DEF':
value = value '3'
elif n[i] in 'GHI':
value = value '4'
elif n[i] in 'JKL':
value = value '5'
elif n[i] in 'MNO':
value = value '6'
elif n[i] in 'PQRS':
value = value '7'
elif n[i] in 'TUV':
value = value '8'
elif n[i] in 'WXY':
value = value '8'
value= value '-'
return AC '-' value[:-1]
new_number = phone_number(number)
print("Input number:",number)
print("New number: ",new_number)
CodePudding user response:
- The inner
for
needs to be indented relative to the outerfor
- The
elif
s need to be on the same indentation as theif
. - The final
value=
line needs to be on the same indentation as one of the two above. Which one depends on what exactly you want the code to do. return
only works inside a function. Your code doesn't contain a function.
CodePudding user response:
elif
s need to be indented same way as if
also after for n in NC:
you are missing indentation, and finally you didn't define function (I am guessing you wanted to name it phone_number
). Here is the fixed version of your code.
number = input("Please enter a phone number:")
characters = number.split('-')
def phone_number(num):
AC = characters[0]
NC = characters[1:]
value = ''
for n in NC:
for i in range(len(n)):
if n[i] in 'ABC':
value = value '2'
elif n[i] in 'DEF':
value = value '3'
elif n[i] in 'GHI':
value = value '4'
elif n[i] in 'JKL':
value = value '5'
elif n[i] in 'MNO':
value = value '6'
elif n[i] in 'PQRS':
value = value '7'
elif n[i] in 'TUV':
value = value '8'
elif n[i] in 'WXY':
value = value '8'
value= value '-'
return AC '-' value[:-1]
new_number = phone_number(number)
print("Input number:",number)
print("New number: ",new_number)