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()
添加回答
舉報