Why is the if statement being ignored?

Imran Chowdhry

I code in C++ and Java. My cousin needed help and I've never experienced Python and decided it was time to get the help of stackoverflow after hours of trying to figure this issue out. Why is the last IF statement not being read while compiling and running the program? I've tried to print a line and the totals. Nothing has worked. Here is the code: Edit: I come for help to learn and seek a sense of direction, why would anyone downvote my reputation. it turns people off from asking questions and is not very user friendly.

'''                        Project 1

  Room Types               Room Rates                Extra Bed Charges          

G = Garden View         Garden View = $185/day      Garden View Room = $15/day
P = Pool View           Pool View   = $195/day      Pool View Room   = $15/day
L = Lake View           Lake View   = $215/day      Lake View Room   = $20/day
                                                    Golf Course      = $25/day
'''

garden_view_rate = 185
pool_view_rate   = 195
lake_view_rate   = 215
seniorDiscount   = .10


TaxRates = { 'State Tax':0.085}

roomTotal=extraBed=TotalDue=0


userInput = ''
loopAgain = True

print 'Welcome to the Ritz Carlton Hotel! Please follow the menu below as our options have recently changed.'

while loopAgain:

    print  '\nG = Garden View'
    print    'P = Pool View'
    print    'L = Lake View'


    userInput = raw_input('Please enter the abbreviation of the desired room type: ').lower()

    if userInput not in ['g','p','l'] :

        print 'Invalid room type, please try again.'
        continue

    num_days = raw_input('Please enter the number of days guest will stay: ')

    userInput = raw_input('Guest need an extra bed? (Y/N) ').lower()

    if userInput not in ['y','n'] :

        print 'Invalid option, please try again.'
        continue

    userInput = raw_input('Will the guest use the Golf Course? (Y/N) ').lower()

    if userInput not in ['y','n'] :

        print 'Invalid option, try again.'
        continue

    userInput = float(raw_input('Please enter the age of the guest: '))


    if userInput == 'g' :
        Amount = int(garden_view_rate + TaxRates['State Tax'])
        print 'Your total balance is: ', Amount
Silas Ray

The last if statement has a condition checking if userInput is equal to 'g'. Given that userInput is always going to be a float, since it was converted as such at input/assignment, it is impossible for that condition to ever evaluate True.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related