此代码是否错误?我收到无效的语法错误。我是高中生的初学者

时间:2019-04-29 21:41:26

标签: python-2.x

我正在编写一个基于您的心情的程序,它将给您报价。有点像激励报价应用程序。尚未完成,我知道列表尚未编程。

import random

UserFeeling_str = raw_input("How are you feeling today?")
 if UserFeeling_str == "upset

 if UserFeeling_str == "sad":

 if UserFeeling_str == "bad":

  if UserFeeling_str == "not great":

      print(random.choice(upset.list))  


if UserFeeling_str == "happy":

 if UserFeeling_str == "good":

 if UserFeeling_str == "okay":

 if UserFeeling_str == "ok":

 print(random.choice(motiv.list))

以及当我运行代码时:

File "/home/ubuntu/workspace/ex50/app.py", line 9
UserFeeling_str = raw_input("How are you feeling today?")
                    ^
SyntaxError: invalid syntax
Process exited with code: 0

2 个答案:

答案 0 :(得分:2)

请注意,它为您提供的错误类型是“语法错误”,这些错误类型通常是由于某个或两个字符的位置错误而丢失或添加了某些东西,即语法为对翻译不利。

仅凭我所见:

如果UserFeeling_str ==“不高兴

需要成为

如果UserFeeling_str ==“烦恼”:

注意引号和冒号。

答案 1 :(得分:2)

您在第一个if句子上缺少“:”。

应该是

error[E0277]: the trait bound `predicates::function::FnPredicate<[closure@core/tests/test_cli.rs:31:48: 37:6], std::string::String>: assert_cmd::assert::IntoOutputPredicate<_>` is not satisfied --> core/tests/test_cli.rs:39:32 | 39 | cmd.arg("hazard").assert().stdout(hazard_predicate); | ^^^^^^ the trait `assert_cmd::assert::IntoOutputPredicate<_>` is not implemented for `predicates::function::FnPredicate<[closure@core/tests/test_cli.rs:31:48: 37:6], std::string::String>` error: aborting due to previous error For more information about this error, try `rustc --explain E0277`.

此外,请不要忘记每个if块上的缩进:

if UserFeeling_str == "upset":