0

So I have a program which has a variable which can be edited by the user. The variable called 'price' is set to 2 as default. I'm trying to print the variable during sentence but it's not working. My code is below:

price = 2

#Definition of 'task_1'.
def task_1():

    #Welcomes the user to the OCR car park.
    print("Welcome to the OCR car park.")

    #Asks for a £2 ticket fee and stores the amount
    #given in a variable called 'ticket_fee'.
    ticket_fee = int(input("Please insert a £",price,"ticket fee: "))
Life is complex
  • 15,374
  • 5
  • 29
  • 58

3 Answers3

1

input() function only takes a single parameter: the string to print. If you want to print a variable inline, then try something like this:

print("Please insert a £",price,"ticket fee: ")
ticket_fee = int(input())
BusyProgrammer
  • 2,783
  • 5
  • 18
  • 31
0
ticket_fee = int(input("Please insert a £" + str(price) + " ticket fee: "))

price should be a string. + should be used for concatenation.

Sunuba
  • 70
  • 2
  • 12
0

I don't think you need an input there as it doesn't have any further job in there as we can judge by your code. Secondly, input is not used to print anything, it works as a prompt to the user (instructions). You should probably be avoiding that. Use print() to call out functions of these types or maybe you can try printing the string in input() throughprint() and use int(input("Whatever you want")) in the next line (if you really need input from the user). Good Luck!