(Apr-10-2017, 02:51 AM)teenspirit Wrote: Here is the Github Repo on that project: https://github.com/dariankbrown/The-5000 You should probably read through the forum post about it and the changes and updates it needs in the forum thread here: https://python-forum.io/Thread-Help-on-a...-the-needy Thanks in advance.
May I make a suggestion? I know this is simple and silly but I've learned to try to avoid even the simplest of bugs. In blocks of code such as:
def main():
# Declaring the necessary variables and dictionary.
large, small = 0, 0
items = {}
while True:
# The following is our main menu that the user will see.
userin = input(
"Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit: ")
if userin == 'i':
food_items(items)
elif userin == 'r':
large, small = one_or_two(large, small)
elif userin == 't':
total(large, small, items)
elif userin == 'e':
total(large, small, items)
final_total(large, small, items)
break
else:
print('An unknown option: ', userin, ' has been entered. Please try the last entry again.')
When entering the string value, if a user enters it in capital letters it will give this traceback:
Error:
/usr/bin/python3.5 "/root/PythonProjects/External_Teachings/The 5000/the_5000.py"
Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit: I
An unknown option: I has been entered. Please try the last entry again.
Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit
This is how I normally avoid this:
def main():
# Declaring the necessary variables and dictionary.
large, small = 0, 0
items = {}
while True:
# The following is our main menu that the user will see.
userin = input(
"Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit: ")
if userin.lower() == 'i':
food_items(items)
elif userin.lower() == 'r':
large, small = one_or_two(large, small)
elif userin.lower() == 't':
total(large, small, items)
elif userin.lower() == 'e':
total(large, small, items)
final_total(large, small, items)
break
else:
print('An unknown option: ', userin, ' has been entered. Please try the last entry again.')
Or you can add an 'or' statement to the string saying...:
if userin == 'i' or 'I':
food_items(items)
You can also avoid ValueErrors silently and still give the else statement that you used by using a try/except/else block so that it makes sure that the correct value must be entered in order to move forward... I guess it's doing this now but I find try/except/else blocks more efficient. Correct me if I am wrong?