简体   繁体   English

无法弄清楚这个无效的语法错误(Python)

[英]Cant figure out this invalid syntax error (Python)

Hey i've been trying to write some stuff for my university projects, right now everything should be working but i keep getting the INVALID SYNTAX error on Line "elif menu==4:" (i'll mark it with \\), i can figure out what i'm doing wrong, any help is really appreciated嘿,我一直在尝试为我的大学项目写一些东西,现在一切都应该正常工作,但是我在“elif menu==4:”行上不断收到 INVALID SYNTAX 错误(我会用 \\ 标记它),我可以弄清楚我做错了什么,非常感谢任何帮助

1)The last digit of a natural number
2)The fraction of a positive number
3)The number of tens inside of a natural number
4)The sum of a 3 digit number
""")
menu=float(input('Please make a selection'))

if menu==1:
    print('Input a Natural number')

    A0 = float(input("input the last digit"))
    A1 = float(input("input the second digit"))
    A2 = float(input("the the third digit"))
    A3 = float(input("the fourth digit"))
    A4 = float(input("any remaning digits"))
    print (A0)

elif menu==2:

   Frac = float(input('Please input the fraction of your number'))

   num = float (input('please input the main body of the nymber'))
   if num < 0:
        print('The number is too low or incorrect please try again.')

        print ('the main part of the number is',(num))
        print ('the fraction of your number is',(Frac))



elif menu==3:
    Num = float(input('Please input a Natural number'))
    if Num < 0:
     print('The number is too low or incorrect please try again.')

print(Num % 10)

\\the line below gets the error.

elif menu==4:

    print ('Please Input a 3 digit number (this program will not work with a longer number)')
    A0 = float(input("input the last digit"))
    A1 = float(input("input the second digit"))
    A2 = float(input("the the third digit"))
    print(A0+A1+A2)```

The issue is the print statement right before your error.问题在于您的错误之前的打印语句。

print(Num % 10)

Remove that and it should work.删除它,它应该可以工作。

The elif statements must be consecutive and the print statement interrupts that and causes the invalid syntax. elif 语句必须是连续的,而打印语句会中断该语句并导致无效的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM