如果我在 python 中编写了一段很长的代码并且我在上面有一个 if else 方法但是想问更多的问题,有没有办法让它忽略上面的代码并且不受缩进的影响?由于缩进,下面不起作用。
或者我只需要将逻辑放在一起而不是分开?
import random
answer = input(
"What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors. ")
if answer == "0":
print(rock)
elif answer == "1":
print(paper)
else:
print(scissors)
choices = [rock, paper, scissors]
number_of_choices = len(choices)
computer = random.randint(0, number_of_choices - 1)
print("The computer chose. \n")
if computer == "0":
print(rock)
elif computer == "1":
print(paper)
else:
print(scissors)
我试图找到一种方法来做到这一点,但做不到。