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)...

  • 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...

  • 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....

  • I am having problems with the following assignment. It is done in the c language. The...

    I am having problems with the following assignment. It is done in the c language. The code is not reading the a.txt file. The instructions are in the picture below and so is my code. It should read the a.txt file and print. The red car hit the blue car and name how many times those words appeared. Can i please get some help. Thank you. MY CODE: #include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char *str; int...

  • This needs to be in python, however, I am having trouble with the code. Is there...

    This needs to be in python, however, I am having trouble with the code. Is there any way to use the code that I already have under the main method? If so, what would be the rest of the code to finish it? #Create main method def main(): #Create empty list list=[] #Display to screen print("Please enter a 3 x 4 array:") #Create loop for rows and have each entered number added to list for i in range(3): list.append([int(x) for...

  • I have a python project that requires me to make a password saver. The major part...

    I have a python project that requires me to make a password saver. The major part of the code is already giving. I am having trouble executing option 2 and 3. Some guidance will be appreciated. Below is the code giving to me. import csv import sys #The password list - We start with it populated for testing purposes passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]] #The password file name to store the passwords to passwordFileName = "samplePasswordFile" #The encryption key for the caesar...

  • I would like some assistance correcting an issue I am having with this assignment. Once a...

    I would like some assistance correcting an issue I am having with this assignment. Once a finite state automaton (FSA) is designed, its transition diagram can be translated in a straightforward manner into program code. However, this translation process is considerably tedious if the FSA is large and troublesome if the design is modified. The reason is that the transition information and mechanism are combined in the translation. To do it differently, we can design a general data structure such...

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
ADVERTISEMENT