473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to use if statement to choose from three choices

I'm trying to get the user to enter what shift they worked, if they enter first shift then the pay rate would be 12.30, if they enter second shift pay rate is 14, and so on.
What I have so far:

Expand|Select|Wrap|Line Numbers
  1. firstShift=12.30
  2. secondShift=14.20
  3. thirdShift=15.30
  4. tax = .28
  5. otMultiplier = .5
  6.  
  7. def main():    
  8.     name = getName()
  9.     hrsWrkd = int(input("Enter hours worked: "))
  10.     shift = getShift()
  11.     payRate = getPayRate(shift)
  12.     display(name,shift)
  13.  
  14. def getName():
  15.     name=input("Enter employee name: ")
  16.     return name
  17.  
  18. def getShift():
  19.     shift = input("Enter shift worked: ")
  20.     return shift
  21.  
  22. def getPayRate(shift):
  23.     payRate = firstShift
  24.     if shift==firstShift:
  25.         return shift
  26.     if shift==secondShift:
  27.         return 
  28.  
  29.  
  30. def display(name,shift):
  31.     print("The pay rate for", name)
  32.     print("Working shift",shift,"is",payRate)
  33.  
  34. main()
  35.  
The part I need help with is the getPayRate part, I'm not sure how choose from the three work shifts.
Mar 12 '13 #1
1 1475
bvdet
2,851 Expert Mod 2GB
I would use a dictionary to contain the pay rates, and return the rate or None which would indicate an invalid answer.
Expand|Select|Wrap|Line Numbers
  1. dd = {'first':12.3, 'second':14.0, 'third': 15.3}
  2.  
  3. def getPayRate(shift):
  4.     return dd.get(shift.lower(), None)
  5.  
  6. print getPayRate('THIRD')
  7. print getPayRate('xxx')
Mar 12 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ghasem | last post by:
Dear mySQL community, I have once again turned to the user groups for a problem I cannot solve myself! Atually, I have read all I can from the newsgroups on this but I could not solve it myself....
7
by: NotGiven | last post by:
I'd like to have several levels of field selection. For example, field one has three choices. Once you choose on form field one, several selections show in field based that ARE BASED ON your...
4
by: Ben | last post by:
I believe I am missunderstanding how subqueries work. I simple subquery works fine but when I wish do compare 2 or more fields at once I don't get the results I wish. Table A...
6
by: Arjen | last post by:
Hi, I'm reading the enterprise library documentation and there I see the throw statement. try { // run code } catch(Exception ex) {
8
by: Rick | last post by:
I am new to ASP.NET I have worked many years in Coldfusion. I am having a problem finding out how to put an IF Statement into the HTML. How do I do this in ASP.NET? Thanks for any help you can...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
4
by: Bob Bedford | last post by:
Hi all, don't know if I must ask in a mysql NG, but this seems more a php question. I've to provide a group of items the user may select or not (checkboxes). The user may choose from 0 to 35...
5
by: dancer | last post by:
I'm using ASP.Net and VB.net I have 18 choices - 18 checkboxes. The user can choose 1, a few, or all. What is the best structure to record and write the response? Select/Case statement? Or is...
6
by: jason | last post by:
Hello, I have a question about what kind of datastructure to use. I'm reading collumn based data in the form of: 10\t12\t9\t11\n 24\t11\t4\t10\n ..... I now have a structure which allows me...
1
flexsingh
by: flexsingh | last post by:
Hello there I have kinda got gotten myself into a sticky situation. I am trying to do something which seams too big to do in my head but I feel I kinda know how to do it. My problem is I have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.