-4

Ticket price depends on age. I am getting an error "invalid literal for value with base 10" in the line

age=int(age)

What does this error mean and how can I solve it? please fix indentation error (if any)

name="\t\n\n WHAT IS YOUR NAME?\t\n\t\t\t"
input(name)
name=str(name)
gender = "\nWhat is your GENDER (M/F) \t\n\t\t\t"
input(gender)
gender=str(gender)
age = "\t\n\tWhat is your age\t\n\t\t\t"
input(age)
age= int(age)
if gender == 'm ':
 gd="Mr. "
elif gender == 'f':
gd="Ms. "
else :
  gd = "_"

price = ['free for kid $0' , '$ 10' , '$15']
if age<=3:
  print("Hello  " + gd + name.title() + "  your Ticket fee is  " + price[0])
elif age <= 12:
  print("Hello "+gd+ name.title() + "  your Ticket fee is  " + price[1])
else:
 print("Hello "+gd+ name.title() + "  your Ticket fee is  " + price[2])

2 Answers2

0

Your code is wrong from the basics. input is the keyword that takes the input from the user as well as shows the input message to the user. You need to store the value to a variable.

So your code should be like that,

name_prompet = "\t\n\n WHAT IS YOUR NAME?\t\n\t\t\t"
name = input(name_prompet)

same it should be with the age,

age_prompet = "\t\n\tWhat is your age\t\n\t\t\t"
age = input(age)

SO at age = int(age) technically you are trying to convert a string into int that's why it's an error.

Tell me if you need anything else.

0

Hi i am also new in Python but as i understand

1- age = "\t\n\tWhat is your age\t\n\t\t\t"
2- input(age)
3- age= int(age)

you can change as below

age = int(input("\t\n\tWhat is your age\t\n\t\t\t"))
  1. line means age is a string which containt this data
  2. read console and set to age variable
  3. try to convert to int and set as same variable

string can carry multi type variable so should be carryfully.

BTW:

  1. for gender 'f' and 'F' is different for python you can add OR condition.
  2. try and catch is good for converting data
doni_darko
  • 16
  • 1