Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14011

My program remembers the variable from previous executions when it shouldn't [closed]

$
0
0

I made this program where the user can input different food names. If the dish is on the dictionary, the cost of that food is added to a counter that is printed. For some reason, the counter doesn't reset when I re-run my program even though I have the counter set to 0 before the loop starts.

menu = {"Baja Taco": 4.25,"Burrito": 7.50,"Bowl": 8.50,"Nachos": 11.00,"Quesadilla": 8.50,"Super Burrito": 8.50,"Super Quesadilla": 9.50,"Taco": 3.00,"Tortilla Salad": 8.00}total = 0\#Loop asks for an item and stops when user inputs ^dwhile True:try:user_input = (input('Item: ')).title()\#total cost countertotal = total + menu\[user_input\]print(f'Total: ${total:.2f}')except KeyError:passexcept EOFError:total = 0print()break

I tried multiple times to re-run my program and it is inconsistent. Sometimes the counter is restarted and other times it isn't.


Viewing all articles
Browse latest Browse all 14011

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>