Python Forum
A CLI based shopping program written in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A CLI based shopping program written in Python
#2
Not bad. A few tips/pointers:

I would put the items in a dictionary. Have the items be keys and the costs be values (as integers). I would think the system would tell you the cost of the thing you purchased. Currently your system allows buying a laptop for 1200.

I don't understand the format on the user_2 input. Why format a string literal with another string literal? Unless you're thinking of expanding to other currencies, put Rs in the first string. Also, I would make the names user_1 and user_2 more descriptive, like user_item and user_cost. It makes your code easier to read.

The in operator and the lower method of strings would greatly simplify your conditionals. Take this line:

while choice == 'n' or choice == 'no' or choice == 'NO' or choice == 'N':
That could be rewritten as:

while choice.lower() in ('n', 'no'):
Now you have all four possibilities taken care of with one operator.

Keep at it.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: A CLI based shopping program written in Python - by ichabod801 - Oct-22-2018, 01:43 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020