To expand on TheAtomicOption's answer, we should first try and perform some validation so that the values in your program are as expected.
Starting with this section:
## Get Employee I.D.
empnum = raw_input('Please enter Employee Number\n')
raw_input
will accept basically anything and return a string value. Assuming that an employee ID is a number, for example, we can try
to convert it to int
and continue asking until a valid value is received.
## Get Employee I.D.
employee_id = None
while employee_id is None:
try:
employee_id = int(raw_input('Please enter Employee Number\n'))
except ValueError:
print "Invalid entry; please enter a valid employee ID."
So now this is what we see at the console:
Please enter Employee Number
hello
Invalid entry; please enter a valid employee number.
Please enter Employee Number
12345
We can apply the exact same kind of validation for ticket and tip amounts.
Some of your names could be made more clear. For instance:
## Lists for the Users input.
amnt = []
amntt =[]
Would be more clear like this:
## Lists for the Users input.
user_tickets = []
user_tips =[]
You have hard-coded 4 tickets and tips. I would recommend instead to ask the user how many tickets they want to enter
# Get number of tickets to enter.
num_tickets = 0
while num_tickets <= 0:
try:
num_tickets = int(raw_input('How many tickets do you want to enter?\n'))
except:
print "Invalid entry for number of tickets."
Then, you can just loop over the number of tickets, applying similar validation along the way. Note that, since those are presumably monetary amounts, we will convert it to float
instead of int
.
## Get Users Input and add to the appropriate list
for ticket in range(0, num_tickets):
ticket_amt = None
tip_amt = None
while ticket_amt is None:
try:
ticket_amt = float(raw_input("Enter ticket {0} amount:\n".format(ticket+1)))
except ValueError:
print "Invalid entry for ticket amount."
while tip_amt is None:
try:
tip_amt = float(raw_input("Enter tip amount:\n"))
except ValueError:
print "Invalid entry for tip amount."
# add to lists once we know we have valid inputs
user_tickets.append(ticket_amt)
user_tips.append(tip_amt)
print "Ticket {0} added with amount {1} and tip {2}".format(ticket+1, ticket_amt, tip_amt)
All that put together, it looks like this in the console:
How many tickets do you want to enter?
2
Enter ticket 1 amount:
20.50
Enter tip amount:
2.25
Ticket 1 added with amount 20.5 and tip 2.25
Enter ticket 2 amount:
15.75
Enter tip amount:
1.50
Ticket 2 added with amount 15.75 and tip 1.5
I would suggest to start making functions to handle things like getting the employee ID, getting tickets, displaying tickets, etc. so you don't have to keep repeating code over and over, you can just call the function instead.
An example:
def get_employee_id():
"""Request employee ID from user"""
employee_id = None
while employee_id is None:
try:
employee_id = int(raw_input('Please enter Employee Number\n'))
except ValueError:
print "Invalid entry; please enter a valid employee ID."
return employee_id
# Do this to get an employee's ID by calling your function:
employeeid = get_employee_id()
Here is a working demo on repl.it.