3 回答

TA贡献1785条经验 获得超8个赞
正确的代码如下所示。
你必须在几个地方意图。
import random
def primary():
print("Keep it logically awesome.")
f = open("quotes.txt")
quotes = f.readlines()
f.close()
last = len (quotes) - 1 #this shud be intented
rnd = random.randint(0, last) #this shud also be intented
print(quotes[rnd]) #this shud be intented
if __name__== "__main__":
primary() #if statements shud always be intented
编写单行 if 语句的另一种方法是
if __name__== "__main__": primary()

TA贡献1827条经验 获得超8个赞
import random
def primary():
print("Keep it logically awesome.")
f = open("quotes.txt")
quotes = f.readlines()
f.close()
last = len(quotes) - 1
rnd = random.randint(0, last)
print(quotes[rnd])
if __name__== "__main__":
primary()
希望这对您有所帮助。享受!

TA贡献1856条经验 获得超5个赞
import random
def primary():
print("Keep it logically awesome.")
f = open("quotes.txt")
quotes = f.readlines()
f.close()
last = len(quotes) - 1
rnd = random.randint(0, last)
print(quotes[rnd])
if __name__== "__main__":
primary()
添加回答
举报