代碼掙扎:Python中不要太用力,只是變
loop = 0
def main():
while loop == 0:
Num = input("Please Enter The Number Of People That Need The Cocktails ")
print()
print(" Type END if you want to end the program ")
print()
for count in range (Num):
with open("Cocktails.txt",mode="w",encoding="utf-8") as myFile:
print()
User = input("Please Enter What Cocktails You Would Like ")
if User == "END":
print(Num, "Has Been Written To The File ")
exit()
else:
myFile.write(User+"/n")
myFile.write(Num+"/n")
print()
print(User, "Has Been Written To The File ")
錯誤:
line 9, in main for count in range (Num): TypeError: 'str' object cannot be interpreted as an integer
我想要的變量設置爲次將重複數他們想要多少雞尾酒。
例子:
How many cocktails ? 6
腳本應該然後要求用戶輸入什麼雞尾酒,他希望六倍。
謝謝你benji :)工作! – user3525198
@亞瑟桑頓,對不起:/問題發佈後我開始寫解決方案,因此我的瀏覽器只有在發佈後才刷新頁面。不太明白你爲什麼不被接受,根據時間戳來判斷,這是早些時候發佈的...另外雖然(True): –
@Alex Thornton我不明白爲什麼,不幸的是,你的答案是早些時候發佈的,但是我和你們一樣,在我的職位上投入了同樣多的精力。你可以自由地複製我的(真):推薦,但我不想刪除我的作品:( –