num_trades = int(input("Number of trades for today?"))

for i in range(1, num_trades + 1):
    action = input("Trade number", i ,"(buy/sell)?")
    num_shares = int(input("Number of shares to buy?"))
    price_per_share = float(input("Price per share?"))

I'm getting a TypeError on the line "action = input("Trade number", i ,"(buy/sell)?")"

Input() function in python is used to get a input value from the command prompt, when the program executes the input() function will display a message(says wat the input is for). it just takes one argument.


mynum = input("Number? ")
Number? 5

in ur code instead of action = input("Trade number", i ,"(buy/sell)?"), u can concatenate like
action = input("Trade number"+ i +"(buy/sell)?")

or do ur way of concatenation outside the input function(if something s seperated by ',' in function argument , it will be considered as an argument itself)

As the error message says, input only expects a single argument (or none), but you give it three. The print function can take multiple arguments and will then just print one after the other (on the same line). The input function does not do that - you have to call it with a single string.

To create a single string for your prompt, you can use the format method like this:

action = input("Trade number {} (buy/sell)?".format(i))
This question has already been answered. Start a new discussion instead.