@Phrancis/

Employee Tickets & Tips

Python 2.7

Review of https://codereview.stackexchange.com/questions/178875/simplify-the-code-in-python-and-any-change-ideas

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.1424960853976358","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyBTT1VSQ0U6DQojIGh0dHBzOi8vY29kZXJldmlldy5zdGFja2V4Y2hhbmdlLmNvbS9xdWVzdGlvbnMvMTc4ODc1L3NpbXBsaWZ5LXRoZS1jb2RlLWluLXB5dGhvbi1hbmQtYW55LWNoYW5nZS1pZGVhcw0KDQojIyBQcm9ncmFtIGdldHMgdGhlIGRhdGUsIEVtcGxveWVlIElELCBhbmQgYW1vdW50cy4gIA0KIyMgSXQgdGhlbiBwbGFjZXMgdGhlbSBpbnRvIGEgdGV4dCBmaWxlIHdoaWNoIGNhbiBiZSBwb3J0ZWQgdG8gZXhjZWwuDQoNCiMjIEdldCBEYXRlDQppbXBvcnQgZGF0ZXRpbWUNCmRhdGUgPSBzdHIoZGF0ZXRpbWUuZGF0ZS50b2RheSgpKQ0KDQpkZWYgZ2V0X2VtcGxveWVlX2lkKCk6DQogICAgIiIiR2V0IGVtcGxveWVlIElEIGZyb20gdXNlciIiIg0KICAgIGVtcGxveWVlX2lkID0gTm9uZQ0KICAgIHdoaWxlIGVtcGxveWVlX2lkIGlzIE5vbmU6DQogICAgICAgIHRyeToNCiAgICAgICAgICAgIGVtcGxveWVlX2lkID0gaW50KHJhd19pbnB1dCgnUGxlYXNlIGVudGVyIEVtcGxveWVlIE51bWJlclxuJykpDQogICAgICAgIGV4Y2VwdCBWYWx1ZUVycm9yOg0KICAgICAgICAgICAgcHJpbnQgIkludmFsaWQgZW50cnk7IHBsZWFzZSBlbnRlciBhIHZhbGlkIGVtcGxveWVlIElELiINCiAgICByZXR1cm4gZW1wbG95ZWVfaWQNCiAgICANCmVtcGxveWVlaWQgPSBnZXRfZW1wbG95ZWVfaWQoKQ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IHRpcF9hbXQgPSBmbG9hdChyYXdfaW5wdXQoIkVudGVyIHRpcCBhbW91bnQ6XG4iKSkNCiAgICAgICAgZXhjZXB0IFZhbHVlRXJyb3I6DQogICAgICAgICAgICBwcmludCAiSW52YWxpZCBlbnRyeSBmb3IgdGlwIGFtb3VudC4iDQogICAgcmV0dXJuIHRpY2tldF9hbXQsIHRpcF9hbXQNCiAgICANCg0KIyMgR2V0IFVzZXJzIElucHV0IGFuZCBhZGQgdG8gdGhlIGFwcHJvcHJpYXRlIGxpc3QNCmZvciB0aWNrZXQgaW4gcmFuZ2UoMCwgbnVtX3RpY2tldHMpOg0KICAgIHRpY2tldF9hbXQsIHRpcF9hbXQgPSBnZXRfdGlja2V0X3RpcF9hbW91bnRzKCkNCiAgICAjIGFkZCB0byBsaXN0cyBvbmNlIHdlIGtub3cgd2UgaGF2ZSB2YWxpZCBpbnB1dHMNCiAgICB1c2VyX3RpY2tldHMuYXBwZW5kKHRpY2tldF9hbXQpDQogICAgdXNlcl90aXBzLmFwcGVuZCh0aXBfYW10KQ0KICAgIHByaW50ICJUaWNrZXQgezB9IGFkZGVkIHdpdGggYW1vdW50IHsxfSBhbmQgdGlwIHsyfSIuZm9ybWF0KHRpY2tldCsxLCB0aWNrZXRfYW10LCB0aXBfYW10KQ0KDQpwcmludCB1c2VyX3RpY2tldHMgDQpwcmludCB1c2VyX3RpcHM="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# SOURCE:
# https://codereview.stackexchange.com/questions/178875/simplify-the-code-in-python-and-any-change-ideas

## Program gets the date, Employee ID, and amounts.  
## It then places them into a text file which can be ported to excel.

## Get Date
import datetime
date = str(datetime.date.today())

def get_employee_id():
    """Get 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
    
employeeid = get_employee_id()

## Lists for the Users input.
user_tickets = []
user_tips =[]

def get_number_of_tickets():
    """Get number of tickets to enter from user"""
    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."
    return num_tickets
    
num_tickets = get_number_of_tickets()

def get_ticket_tip_amounts():
    """Get the ticket and tip amounts from user"""
    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."
    return ticket_amt, tip_amt
    

## Get Users Input and add to the appropriate list
for ticket in range(0, num_tickets):
    ticket_amt, tip_amt = get_ticket_tip_amounts()
    # 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)

print user_tickets 
print user_tips