Question

In: Computer Science

This is in Python I am getting an error when I run this program, also I...

This is in Python I am getting an error when I run this program, also I cannot get any output. Please help!

#Input Section
def main():
name=input("Please enter the customer's name:")
age=int(input("Enter age of the customer: "))
number_of_traffic_violations=int(input("Enter the number of traffic violations: "))
if age <=15 and age >= 105:
print('Invalid Entry')
if number_of_traffic_violations <0:
print('Invalid Entry')

#Poccessing Section

def Insurance():
if age < 25 and number_of_tickets >= 4 and riskCode == 1:
insurancePrice = 480
elif age >= 25 and number_of_tickets >= 4 and riskCode == 1:
insurancePrice = 410
elif age < 25 and number_of_tickets == 3 and riskCode == 2:
insurancePrice = 450
elif age >= 25 and number_of_tickets == 3 and riskCode == 2:
insurancePrice = 390
elif age < 25 and number_of_tickets == 2 and riskCode == 2:
inurancePrice = 405
elif age >= 25 and number_of_tickets == 2 and riskCode == 2:
insurancePrice = 365
elif age < 25 and number_of_tickets == 1 and riskCode == 3:
insurancePrice = 380
elif age >= 25 and number_of_tickets == 1 and riskCode == 3:
insurancePrice = 315
elif age < 25 and number_of_tickets == 0 and riskCode == 4:
insurancePrice = 325
elif age >= 25 and number_of_tickets == 0 and riskCode == 4:
insurancePirce = 275
else:
insurancePrice = 0
  
def calc():
if number_of_traffic_violations >=4:
riskCode = 1
riskType = 'high'
elif number_of_traffic_violations == 3:
riskCode = 2
riskType = 'moderate'
elif number_of_traffic_violations == 2:
riskCode =3
riskType = 'moderate'
elif number_of_traffic_violations == 1:
riskCode = 4
riskType = 'low'
elif number_of_traffic_violations == 0:
riskCode = 5
riskType = 'no'
else:
riskCode = 0
riskType = 0


# OUTPUT SECTION
print(name,' as a ', riskType , ' risk driver, insurance Price will cost $', format(insurancePrice, '.2f'))

main()

Solutions

Expert Solution

I have observed the Code

Note:Don't Directly Copy Paste from the Code Provided here. Because this Editor is Adding Some Error Element to it.

Paste it in a text file and type the code into your file.To get No errors.And Ignore Comments

1)the Main error is Indentation .But I haven't Seen You code Indented.

INDENTATION means making a group of statements into block by providing equal spacing before it.

2) Haven't defined number_of_tickets variable.

3)You have defined the methods but Not calling them .

Fixes:

1)I have made each function properly indented.

2)Inserted a input statement for taking no of tickets

3)Indented the code into three functions like main(),Insurance(),calc().And passed the Argument to each function.And Made each function return some values and stored it in some variable for further usage.

4) I moved the output Section into the Main() it Self .And from Main I called Both calac(),insurance()

Suggestion:

The If conditions are very complex So verify them Whether you inserted all the Condition or Not properly

Code in PYTHON 3:

def main():
name=input("Please enter the customer's name:")
age=int(input("Enter age of the customer: "))
number_of_traffic_violations=int(input("Enter the number of traffic violations: "))
# line I added
number_of_tickets=int(input("Enter Number of Tickets"))
  
if age <=15 and age >= 105:
print('Invalid Entry')
if number_of_traffic_violations <0:
print('Invalid Entry')
else:
#lines I added
riskCode,riskType=calc(number_of_traffic_violations)
  
insurancePrice=Insurance(number_of_tickets,riskCode,age)
  
print(name,' as a ', riskType , ' risk driver, insurance Price will cost $', format(insurancePrice, '.2f'))


#Poccessing Section

def Insurance(number_of_tickets,riskCode,age):
if age < 25 and number_of_tickets >= 4 and riskCode == 1:
insurancePrice = 480
elif age >= 25 and number_of_tickets >= 4 and riskCode == 1:
insurancePrice = 410
elif age < 25 and number_of_tickets == 3 and riskCode == 2:
insurancePrice = 450
elif age >= 25 and number_of_tickets == 3 and riskCode == 2:
insurancePrice = 390
elif age < 25 and number_of_tickets == 2 and riskCode == 2:   
insurancePrice = 405
elif age >= 25 and number_of_tickets == 2 and riskCode == 2:
insurancePrice = 365
elif age < 25 and number_of_tickets == 1 and riskCode == 3:
insurancePrice = 380
elif age >= 25 and number_of_tickets == 1 and riskCode == 3:
insurancePrice = 315
elif age < 25 and number_of_tickets == 0 and riskCode == 4:
insurancePrice = 325
elif age >= 25 and number_of_tickets == 0 and riskCode == 4:
insurancePrice = 275
else:
insurancePrice = 0
return insurancePrice
  
def calc(number_of_traffic_violations):
riskCode=0
if number_of_traffic_violations >=4:
riskCode = 1
riskType = 'high'
elif number_of_traffic_violations == 3:
riskCode = 2
riskType = 'moderate'
elif number_of_traffic_violations == 2:
riskCode =3
riskType = 'moderate'
elif number_of_traffic_violations == 1:
riskCode = 4
riskType = 'low'
elif number_of_traffic_violations == 0:
riskCode = 5
riskType = 'no'
else:
riskCode = 0
riskType = 0
return riskCode,riskType

main()

code ended here

HAve A great Day!


Related Solutions

I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
What am i doing wrong. I want for the program to run through then when it...
What am i doing wrong. I want for the program to run through then when it gets to "do you want to play again?enter yes or no" if they choose yes I want it to run again if they choose no then end. def play(): print("Welcome to the Game of Life!") print("A. Banker") print("B. Carpenter") print("C. Farmer") user_input = input("What is your occupation? ").upper() if user_input == "A": money = 100 elif user_input == "B": money = 70 elif user_input...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
when i run the program on eclipse it gives me this error: Exception in thread "main"...
when i run the program on eclipse it gives me this error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0    at SIM.main(SIM.java:12) how do I fix that ? (please fix it ) import java.util.*; import java.util.Scanner; import java.util.ArrayList; import java.io.File; import java.io.FileNotFoundException; import java.lang.Math; public class SIM{    public static void main(String[] args) throws FileNotFoundException {       int cacheSize = Integer.parseInt( args[1] ); int assoc = Integer.parseInt( args[2] ); int replacement = Integer.parseInt(...
I am making a html game with phaser 3 I keep getting an error at line...
I am making a html game with phaser 3 I keep getting an error at line 53 of this code (expected ;) I have marked the line that needs to be fixed. whenever I add ; my whole code crashes const { Phaser } = require("./phaser.min"); var game; var gameOptions = {     tileSize: 200,     tileSpacing: 20,     boardSize: {     rows: 4,     cols: 4     }    }    window.onload = function() {     var gameConfig = {         width: gameOptions.boardSize.cols * (gameOptions.tileSize +             gameOptions.tileSpacing) + gameOptions.tileSpacing,...
I am getting an error at linen 57 and can't figure out how to fix it....
I am getting an error at linen 57 and can't figure out how to fix it. // Java program to read a CSV file and display the min, max, and average of numbers in it. import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main {     // method to determine and return the minimum number from the array     public static int minimum(int numbers[])     {         int minIdx = 0;         for(int i=1;i<numbers.length;i++)         {             if((minIdx...
Why am I getting the error: ValueError: The truth value of a Series is ambiguous. Use...
Why am I getting the error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() Fielding is a DataFrame, but I am not sure why I am getting this error. Any help would be appreciated! RAR = [] for i in range(0,len(Fielding)): position = (Fielding['POS'][i]) value = 0 if position == 'C': value = (9.0/150.0) * (Fielding['GS'][i]) elif position == 'SS': value = (7.0/150.0) * (Fielding['GS'][i]) elif position == '2B': value = (3.0/150.0)...
Develop the following code for quiz (i am getting some errors)in python in such a manner...
Develop the following code for quiz (i am getting some errors)in python in such a manner that it shoulde be having extra 3 attempts(for wrong answrs) for all questions if the user entered wrong answer · for ex: If the user entered correct answer for first question #then 3 attempts will be carried to next questions. If the user entered 3 times wrong answer in 1st question itself means it sholud display as no more attempts and you got o...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT