![](/img/trans.png)
[英]Generating a menu for a tkinter window doesn’t work using a function but works just fine if the steps are executed on a python console
[英]my python code doesn't get executed. No error, no process finished text just blank. Other codes works fine
list1 = ["5", "-", "2", "+", "1"]
int_list = []
while len(list1) > 0:
if len(int_list) < 1:
int_list.append(int(list1[0]))
list1.pop(0)
int_list.append(0)
int_list.append(int(list1[1]))
int_list.pop(0)
int_list.pop(0)
print(int_list)
我正在嘗試制作計算器。 但是這段代碼不執行。 就像沒有錯誤沒有文本只是空白。 有誰知道為什么會這樣?
條件len(list1) > 0
將始終為True
因為您沒有從list1
中刪除任何項目。
為此,您需要更換
list1.pop(0)
-> del list1[0]
和
int_list.pop(0)
-> del int_list[0]
您必須使用del
刪除特定索引處的項目
有一些錯誤(剛剛在之前的帖子中提到),所以我不會重復。
您似乎開始實施一些堆棧數據結構來進行一些數學評估。 偉大的。 這里有一些建議和代碼片段供您開始使用。
首先,嘗試使用有意義但簡潔的變量名。 其次,在論文和流程圖中寫一些偽代碼,最后實現。 第一次成功的機會要好得多..
L = ["5", "-", "2", "+", "1"]
eval_lst = list()
for i, x in enumerate(L):
try:
eval_lst.append(int(x))
except ValueError:
eval_lst.append(x)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.