我在Python中有无效的语法

问题描述 投票:-2回答:2

我是这个论坛的新东西和python的新手。请温柔。 我试图解决它,但它仍然无法正常工作。我真的很紧张救命。

print('Print')
input('make space by pressing space')
print('Thanks for the space, space, space, spaceeeeeeee.')
input('read this? (press to continue)')
print('also thanks for your time')
print('What is your age')
age = input()
#age
print('In 42 years you will be:' + str(int(age) + 42) + ' years old')
print('Also, did you read "Hitchhikers guide to the galaxy"?')
print('Anwser with "true" or "false"')
hgttg = input()
#if's are coming
if hgttg == 'true'
   print('Ah, you earned my respect')
   input('good (press to continue)')
   else
   print('Ok, you can read it another day, you are still conversing with 
   me')
   input('this time no respect (press to continue)')
   #water adventure   
   print('Can you bring me a glass of water, please?')
   print('Again, anwser with either "true" or "false"')
   boolwater = input()
   if boolwater == 'true'
   print('Thanks!')
   input('press to continue')
   else
   print('I will go get it myself ')
   input('youve angered me (press to continue)')

    print('Thanks for talking to me, and see you another time!')
    input('Press to exit')
python python-3.x
2个回答
0
投票

你的indentations关闭并且在你的:结束时缺少if/ else statements冒号

if hgttg == 'true':
    print('Ah, you earned my respect')
    input('good (press to continue)')
else:
    print('Ok, you can read it another day, you are still conversing with me')
    input('this time no respect (press to continue)')
    #water adventure   
    print('Can you bring me a glass of water, please?')
    print('Again, anwser with either "true" or "false"')
    boolwater = input()
    if boolwater == 'true':
        print('Thanks!')
        input('press to continue')
    else:
        print('I will go get it myself ')
        input('youve angered me (press to continue)')
print('Thanks for talking to me, and see you another time!')
input('Press to exit')

0
投票

您的语法问题是您需要使用空格或制表符来编写正文。

if conditions :
    print("conditions are true")
else :
    print("they are not true")

如你所见,我用空间来分隔身体。

© www.soinside.com 2019 - 2024. All rights reserved.