x = 30
y = 60
if (x>y):
print("True")
else:
print("False")
错误
File "<ipython-input-1-05aca812b623>", line 7
else:
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
else
必须与if
垂直对齐。
答案 1 :(得分:0)
我认为问题是缩进 请尝试以下。
x = 30
y = 60
if (x>y):
print("True")
else:
print("False")
答案 2 :(得分:0)
此代码运行正常。
while True:
userResponse = str(input("Please enter name of guest: "))
if userResponse == 'quit':
for index, userResponse in enumerate(list):
print(f'Guest {index + 1} is {userResponse}')
userDelete = input('Do you want to delete any users? If so type their corresponding number to delete or type "quit" to print list and end program.')
if userDelete == 'quit':
for index, userResponse in enumerate(list):
print(f'Guest {index + 1} is {userResponse}')
break
elif userDelete in list:
list.pop(userResponse)
for index, userResponse in enumerate(list):
print(f'Guest {index + 1} is {userResponse}')
break
elif userDelete not in list:
print('You tried deleting a name that is not in the list, please try again.')
userDelete
list.pop(userResponse)
elif userResponse not in list:
list.append(userResponse)
elif userResponse in list:
print('Name already in list, try another or enter "quit" to show list of guests.')
userResponse
缩进在python中非常重要。确保您正确缩进代码。
答案 3 :(得分:0)
缩进在python中很重要。正确缩进您的代码,它将正常工作。
x = 30
y = 60
if (x>y):
print("True")
else:
print("False")