繁体   English   中英

Python If / Else语句

[英]Python If/Else Statements

当涉及到python时,我是一个新手。

但是我无法获得这段代码。 我花了很长时间试图在各种书籍和问题站点中找出问题所在,所以我来到了这里。

我的python idle(Python GUI) (我正在使用的软件)每当我使用Else语句时都会不断出现语法错误...

a = str
print("What is Your name")
a = input()
b = str
print("Oh Hello " + a)
print("How Are You Feeling")
b = input()
if b == "Happy":
    print("Glad to hear that":
          else:
          print("Oh im sorry to hear that")

抱歉,这是与计算机的对话,但是我从来没有选择主题,所以我无济于事...

请帮忙

缩进在Python中很重要。 else必须缩进量相同的if与它配对:

a = str
print("What is Your name")
a = input()
b = str
print("Oh Hello " + a)
print("How Are You Feeling")
b = input()
if b == "Happy":
    print("Glad to hear that")   # Added the missing ) here as well
else:
    print("Oh im sorry to hear that")

else语句的缩进必须与其相应的if相同。 在打印末尾您也缺少a ) ,并且在打印末尾不需要:

if b == "Happy":
    print("Glad to hear that")  # <== missing that last ), you don't need that :
else:  # <== indentation was wrong here
    print("Oh im sorry to hear that")

暂无
暂无

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

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