Question

I am completing a rental car project in python. I am having syntax errors returned. currently...

I am completing a rental car project in python. I am having syntax errors returned. currently on line 47 of my code "averageDayMiles = totalMiles/daysRented" my entire code is as follows:

#input variable
rentalCode = input("(B)udget , (D)aily , (W)eekly rental? \n")
if(rentalCode == "B"):
rentalPeriod = int(input("Number of hours rented?\n"))
if(rentalCode == "D"):
rentalPeriod = int(input("Number of days rented?\n"))
if(rentalCode == "W"):
rentalPeriod = int(input("Number of weeks rented?\n"))
rentalPeriod = daysRented
return rentalCode , rentalPeriod

budget_charge = 40.00
daily_charge = 60.00
weekly_charge = 190.00

#if, elif, else branch
if(rentalCode == "B"):
print(baseCharge = rentalPeriod * 40.00)
elif(rentalCode == "D"):
print(baseCharge = rentalPeriod * 60.00)
else:
print(baseCharge = rentalPeriod * 190.00)

print(rentalCode)
print(rentalPeriod)

#If, elif, else branch
if(rentalCode == "B"):
print(baseCharge = budgetCharge * rentalPeriod)
elif(rentalCode == "D"):
print(baseCharge = dailyCharge * rentalPeriod)
else:
print(baseCharge = weeklyCharge * rentalPeriod)

#input variables
odoStart = int(input("Starting Odometer Reading:\n"))
odoEnd = int(input("Ending Odometer Reading:\n"))
totalMiles = (odoEnd - odoStart)
#command=print
print(odoStart)
print(odoEnd)

#input variable
mileCharge = int(input(totalMiles * 0.25)
#inputvariables and if, else'
#averageDayMiles
averageDayMiles = totalMiles/daysRented
extraMiles = averageDayMiles - 100
if(averageDayMiles <= 100):
print(0)
else:
print(extramiles)

#input variable and if else
averageWeekMiles = input(totalMiles/rentalPeriod)
if(averageWeekMiles > 900):
mileCharge = 100.00/week
else:
milecharge = 0.00

#
print('Rental Summary')
print('Rental Code: '+str(rentalCode))
print('Days Rented: '+str(rentalPeriod))
print('Starting Odometer: ' + (odoStart))
print('Ending Odometer: ' + (odoEnd))
print('Miles Driven: '+str(totalMiles))
print('Amount Due: $'+ "%.2f"%(amtDue))   
  

what is wrong with this?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

First thing i'm using python 2.7 i have implemented code using raw_input to take input

(instead of input i'm using raw_input) please go to bottom to get whole code of program

I also submitted output of program please go through it for better understanding.

Problems in above code are as follows -

1) Intendetion should be proper .Intendetion is important in python it sholud like below code.

if(rentalCode == "B"):
rentalPeriod = int(input("Number of hours rented?\n"))
if(rentalCode == "D"):
rentalPeriod = int(input("Number of days rented?\n"))
if(rentalCode == "W"):

2) You can not return two values in else statement and another problem is

if(rentalCode == "W"):
rentalPeriod = int(input("Number of weeks rented?\n"))
rentalPeriod = daysRented #here you assigning daysRented variable value rentalPeriod but unfortunately you haven't declare  
return rentalCode , rentalPeriod #In case you can want print this variable value you can print it outside the else

rentalCode = raw_input("(B)udget , (D)aily , (W)eekly rental? \n")
if(rentalCode == "B"):
rentalPeriod = int(raw_input("Number of hours rented?\n"))
if(rentalCode == "D"):
rentalPeriod = int(raw_input("Number of days rented?\n"))
if(rentalCode == "W"):
rentalPeriod = int(raw_input("Number of weeks rented?\n"))


print(rentalPeriod) #outside else condition
print(rentalCode)   #outside else condition

3) You have declare three variables in your code

budget_charge = 40.00
daily_charge = 60.00
weekly_charge = 190.00

You have use budgetCharge , dailyCharge and  rentalPeriod in your code but this variable are not declare in code

print(baseCharge = budgetCharge * rentalPeriod)

print(baseCharge = dailyCharge * rentalPeriod)

print(baseCharge = rentalPeriod * 190.00)

solution for this -

You should write above code in this format with variable name change you can use

budget_charge = 40.00
daily_charge = 60.00
weekly_charge = 190.00

baseCharge = budget_charge * rentalPeriod

baseCharge = daily_charge * rentalPeriod

baseCharge = weekly_charge * 190.00

print(baseCharge)

Your code will look like this .

4) The mail issue that you have mention in question error on line number 47

You have written below statement on line number 47

averageDayMiles = totalMiles/daysRented

but if you observed there is input statement just above this line and that line missing a closing parenthesis

mileCharge = int(raw_input(totalMiles * 0.25) # this statement should be

mileCharge = int(raw_input(totalMiles * 0.25)) # please observed closing parenthesis ( ')' ) at the end

5) In your code

mileCharge = 100.00/week

You have 'week' variable but i haven't seen any variable named week in your code i think it should be rentalPeriod to calculate mile charge.

mileCharge = 100.00/rentalPeriod #it should like this and

6) In Your code

print('Amount Due: $'+ "%.2f"%(amtDue))   

In above statement amtDue variable is not declared in your program i don't know how your calculating this but it will through error if variable is not declared .

so i commented that statement in below final code

########## Program ############

# Program Code

# raw_input variable
rentalCode = raw_input("(B)udget , (D)aily , (W)eekly rental? \n")
if(rentalCode == "B"):
rentalPeriod = int(raw_input("Number of hours rented?\n"))
if(rentalCode == "D"):
rentalPeriod = int(raw_input("Number of days rented?\n"))
if(rentalCode == "W"):
rentalPeriod = int(raw_input("Number of weeks rented?\n"))


print(rentalPeriod)
print(rentalCode)

budget_charge = 40.00
daily_charge = 60.00
weekly_charge = 190.00

# if, elif, else branch
if(rentalCode == "B"):
baseCharge = rentalPeriod * 40.00
print(baseCharge)
elif(rentalCode == "D"):
baseCharge = rentalPeriod * 60.00
print(baseCharge)
else:
baseCharge = rentalPeriod * 190.00
print(baseCharge)

# If, elif, else branch
if(rentalCode == "B"):
baseCharge = budget_charge * rentalPeriod
print(baseCharge)
elif(rentalCode == "D"):
baseCharge = daily_charge * rentalPeriod
print(baseCharge)
else:
baseCharge = weekly_charge * rentalPeriod
print(baseCharge)

# raw_input variables
odoStart = int(raw_input("Starting Odometer Reading:\n"))
odoEnd = int(raw_input("Ending Odometer Reading:\n"))
totalMiles = int(odoEnd - odoStart)
# command=print
print(odoStart)
print(odoEnd)

# raw_input variable
mileCharge = int(totalMiles * 0.25)
# raw_inputvariables and if, else'
# averageDayMiles
averageDayMiles = totalMiles/rentalPeriod
extraMiles = averageDayMiles - 100
if(averageDayMiles <= 100):
print(0)
else:
print(extraMiles)

# raw_input variable and if else
averageWeekMiles = raw_input(totalMiles/rentalPeriod)
if(averageWeekMiles > 900):
mileCharge = 100.00/rentalPeriod
else:
milecharge = 0.00

#
print('Rental Summary')
print('Rental Code: '+str(rentalCode))
print('Days Rented: '+str(rentalPeriod))
print('Starting Odometer: ' ,(odoStart))
print('Ending Odometer: ' , (odoEnd))
print('Miles Driven: '+str(totalMiles))

#print('Amount Due: $'+ "%.2f"%(amtDue))   

#Output -

Add a comment
Know the answer?
Add Answer to:
I am completing a rental car project in python. I am having syntax errors returned. currently...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Code comments explain and facilitate navigation of the code python import sys rentalcode = input("(B)udget, (D)aily,...

    Code comments explain and facilitate navigation of the code python import sys rentalcode = input("(B)udget, (D)aily, or (W)eekly rental?\n").upper() if rentalcode == 'B' or rentalcode == 'D': rentalperiod = int(input("Number of Days Rented:\n")) else: rentalperiod = int(input("Number of Weeks Rented:\n")) # Pricing budget_charge = 40.00 daily_charge = 60.00 weekly_charge = 190.00 #Second Section 2 odostart =int(input("Starting Odometer Reading:\n")) odoend =int(input("Ending Odometer Reading:\n")) totalmiles = int(odoend) - int(odostart) if rentalcode == 'B': milecharge = 0.25 * totalmiles if rentalcode == "D":...

  • Section 1: Collect customer input ''' rentalCode = input('(B)udget, (D)aily, or (W)eekly rental?\n') if rentalCode ==...

    Section 1: Collect customer input ''' rentalCode = input('(B)udget, (D)aily, or (W)eekly rental?\n') if rentalCode == 'B' or rentalCode == 'D': rentalPeriod = int(input('Number of Days Rented:\n')) else: rentalPeriod = int(input('Number of Weeks Rented:\n')) daysRented = rentalPeriod #Assigning a dollar amount (double floating number) to the varying rates budget_charge = 40.00 daily_charge = 60.00 weekly_charge = 190.00 #baseCharge changes value based on the type of rental code using multiplication #Each branch of if or elif assignes a different value to...

  • what am I missing? this should be the output: (B)udget, (D)aily, or (W)eekly rental? B Starting...

    what am I missing? this should be the output: (B)udget, (D)aily, or (W)eekly rental? B Starting Odometer Reading: Ending Odometer Reading: 1234 2222 988 247.00 my output is this: (B)udget, (D)aily, or (W)eekly rental? Starting Odometer Reading: Ending Odometer Reading: 1234 2222 988 247.00 here's my code so far: import sys ''' Section 1: Collect customer input ''' #Add customer input 1 here, rentalCode = input("(B)udget, (D)aily, or (W)eekly rental?") #Collect Customer Data - Part 2 #4)Collect Mileage information: ##a)...

  • BELOW CODE DONE IN CODIO AND PASSED THE FIRST SET OF CHECKS FOR COLLECT CUSTOMER DATA...

    BELOW CODE DONE IN CODIO AND PASSED THE FIRST SET OF CHECKS FOR COLLECT CUSTOMER DATA PART 2 (CODIO) CHECK INSTRUCTIONS BELOW - PASSED Collect Customer Data - Part 2 Collect Mileage information: Prompt: "Starting Odometer Reading:\n" Variable: odoStart = ? Prompt: "Ending Odometer Reading:\n" Variable: odoEnd = ? Add code to PRINT odoStart and odoEnd variables as well as the totalMiles to check your work. The following data will be used as input in the test: odoStart = 1234...

  • Calculate the base charge if rentalCode == 'B': baseCharge = rentalPeriod * budgetCharge Set the base...

    Calculate the base charge if rentalCode == 'B': baseCharge = rentalPeriod * budgetCharge Set the base charge for the rental type equal to the variable baseCharge. The base charge is the rental period * the appropriate rate: For example: Finish the conditional statement by adding the conditions for other rental codes. import sys ''' Section 1: Collect customer input ''' # For holding cost of miles drive mileCharge = 0 # Reading type of rental rentalCode = input("(B)udget, (D)aily, or...

  • Collect Customer Data - Part 1 Hint: This input code is similar to the code in...

    Collect Customer Data - Part 1 Hint: This input code is similar to the code in the previous step but use a conditional statement to test if the rentalPeriod is a daily or weekly rental then set the user input equal to rentalPeriod. Add code to PRINT the rentalCode and rentalPeriodvariables to check your work. The following data will be used as input in the first check: rentalCode = 'D' rentalPeriod = 5 Customer Data Check 1A Check It!SHOW DIFF...

  • I am having trouble with my Python code in this dictionary and pickle program. Here is...

    I am having trouble with my Python code in this dictionary and pickle program. Here is my code but it is not running as i am receiving synthax error on the second line. class Student: def__init__(self,id,name,midterm,final): self.id=id self.name=name self.midterm=midterm self.final=final def calculate_grade(self): self.avg=(self.midterm+self.final)/2 if self.avg>=60 and self.avg<=80: self.g='A' elif self.avg>80 and self.avg<=100: self.g='A+' elif self.avg<60 and self.avg>=40: self.g='B' else: self.g='C' def getdata(self): return self.id,self.name.self.midterm,self.final,self.g CIT101 = {} CIT101["123"] = Student("123", "smith, john", 78, 86) CIT101["124"] = Student("124", "tom, alter", 50,...

  • Propose: In this lab, you will complete a Python program with one partner. This lab will...

    Propose: In this lab, you will complete a Python program with one partner. This lab will help you with the practice modularizing a Python program. Instructions (Ask for guidance if necessary): To speed up the process, follow these steps. Download the ###_###lastnamelab4.py onto your desktop (use your class codes for ### and your last name) Launch Pyscripter and open the .py file from within Pyscripter. The code is already included in a form without any functions. Look it over carefully....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT