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

Why am I getting this error using 000webhost , but I do not get this error...
Why am I getting this error using 000webhost , but I do not get this error running XAMPP? Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd2/006/14881006/public_html/test/index.php:1) in /storage/ssd2/006/14881006/public_html/test/index.php on line 8 Code is below. ******************************************************************************************************************** <!DOCTYPE html> <?php    //Determine if the submit button has been clicked to set the cookie name and value    if (isset($_POST['name'])){            $cookie_name = $_POST['name'];            $cookie_value = $_POST['value'];            setcookie($cookie_name, $cookie_value,...
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        ...
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...
I am struggling with this assignment. I can't get the program to run when I enter...
I am struggling with this assignment. I can't get the program to run when I enter a number with the $ symbol followed by a number below 10. any help would be greatly appreciated. Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded methods that accept an int, double, or string bid. Each method should display the bid and indicate whether it is over the minimum acceptable...
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);...
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?
I get an error when im trying to run this java program, I would appreciate if...
I get an error when im trying to run this java program, I would appreciate if someone helped me asap, I will make sure to leave a good review. thank you in advance! java class Node public class Node { private char item; private Node next; Object getNext; public Node(){    item = ' '; next = null; } public Node(char newItem) { setItem(newItem); next = null; } public Node(char newItem, Node newNext){ setItem(newItem); setNext(newNext); } public void setItem(char newItem){...
Hi I am getting error in implement some test case using Java. I am adding my...
Hi I am getting error in implement some test case using Java. I am adding my code and relevant files here, and the failed test. Please let me know where my problem is occuring and fix my code. Thanks! I will upvote. Implement a class to perform windowing of a Hounsfield value Implement the class described by this API. A partial implementation is provided for you in the eclipse project; however, unlike the previous class, very little work has been...
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,...
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(...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT