13,664,248 members
See more:
I am currently writing a program in python to determine rates for bowling, check if specials are applicable, and returning the cost per person. I must define three functions using assignment and if/else statements.

I wrote the code, however it is failing all tests that I put it through. Can someone look it over and tell me if there is a logical error? I have used python visualizer and it shows that it should work, however; it does not.

What I have tried:

```def get_rate(start_hr, start_min, day, is_holiday):
if (is_holiday ==True):
if (start_hr <=18) and (start_min >=29):
rate=4
return 4
else:
rate=6
return 6
else:
if (day <=4):
if (start_hr <=18) and (start_min <30):
rate= 3
return 3
else:
rate=5
return 5
else:
if (day == 5):
if (start_hr <=18) and (start_min >=29):
rate=3
return 3
else:
rate=6
return 6
else:
if (day >=6):
if (start_hr <= 18) and (start_min >=29):
rate=4
return 4
else:
rate=6
return 6

def check_nite(start_hr, start_min, day):
if (day <=5) and (start_hr>=21) and (start_min >=30):
return True
else:
return False

def get_fee(rate, num_games, num_people, day, is_nite, is_holiday):
cost=(rate*num_games)*num_people
if is_holiday== True:
return ('Happy holidays! your total is \$', cost, '.')
else:
if is_nite== True:
if day <=4
rate=7
num_games=1
return ('nite special! your total is \$', cost,'.')
else:
rate=14
num_games=1
return 14
else:
if (day == 6) and (num_people>=4):
rate=2
return ('thrifty sunday! your total is \$', cost, '.')
else:
return ('your total is \$', cost,'.')```
Posted 15-Feb-17 4:40am
Updated 15-Feb-17 7:54am
v2

## Solution 1

There are many issues with your code:
1. Your code is very messy and riddled with a lot of if else statements, many of which can be better organized using if..elif..else.
2. You are setting rate variable in the get_rate function but never used it, why?
3. in this function:
`def get_fee(rate, num_games, num_people, day, is_nite, is_holiday):`
, some of your code are assigning values to the function arguments instead of using them, e.g.
```rate=7
num_games=1```
and they are never used thereafter.
4. Watch out for syntax error, e.g.
`if day <=4`
Get your house in order before considering any testing.
v2

## Solution 2

Even if I am not a Java user, I see that you try to return 3 values in this line
`return ('Happy holidays! your total is \$', cost, '.')`

I suspect it is wrong. This line line will not build a string from the 3 values.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.

Top Experts
Last 24hrsThis month
 OriginalGriff 270 Richard MacCutchan 105 Gerry Schmitz 105 Jochen Arndt 80 Dave Kreskowiak 80
 OriginalGriff 3,597 Richard MacCutchan 1,472 ppolymorphe 1,302 Jochen Arndt 1,217 Dave Kreskowiak 773