I am doing a project on passing arguments through functions. My problem is that I am writing a program that gives the charged amount based on age and traffic violations. Here is my current code:
print("Use this program to estimate your liability.")
def main():
user_name()
age()
violations()
risk_code()
#Input#
#Def for name
def user_name():
user_name = print(input("What is your name?"))
#Def for age
def age():
age = int(input("What is your age?"))
#Def for traffic violations (tickets.)
def violations():
violation = print(input("How many traffic violations (tickets) do you have?"))
#Process#
def risk_code(violation):
if violation == 0 and age >= 25:
risk = "None"
cost = int(275)
#How many tickets to indicate risk code (therefore risk type)
# Age + traffic violations (tickets) = risk code
# Age + Traffic violations + Risk Code = Price
#Output#
#Def for customer name
# Def for risk output
# Def for cost
main()
I want the program to display how much the customer owes if I were to select my age as 25, with zero violations. The issue is I keep getting a positional argument error. I am a little confused on what this means. Could anyone provide help/example?
You have several issues in your code:
The positional argument error is caused because you call
risk_code()
func without providing it the argument it needs:violation
.user_name = print(input("What is your name?"))
- user_name will beNone
sinceprint
function returns nothing. Actually, you don't need toprint
in order to output your message,input
does it for you.You have to add
return
to your functions in order to be able to pass your variables which are defined inside the function scope into other functions. For example, inviolations()
function,violation
variable is defined inside the scope of the function and without returning it, you won't be able to use it somewhere else in your code.I made some changes in your code, try it:
There are still improvements to do (
user_name
is unused for example) but it might be a good start.