Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a variable inside of an input statement? [duplicate]

def main():
    total = 0.0
    totalcom = 0.0
    name = input("Please enter your name: ")
    for x in range(1, 8):
        sales = float(input("Please enter your sales from day", x))

        total += sales
        commission = sales * .1
        totalcom += commission

    print("Your total sales is: ", total)
    print("Your commission is: ", totalcom)


main()

My goal is essentially a commission calculator. I am supposed to get the amount of sales per day from the user. However, I would like the user to know what day the information they are entering is for. The error I get says "input expected at most one arguments, got 2". So is there a way to use x in my input statement?

like image 763
Derrick Avatar asked Sep 30 '16 23:09

Derrick


People also ask

Can you put a variable in an input statement Python?

There are two functions that can be used to read data or input from the user in python: raw_input() and input(). The results can be stored into a variable. raw_input() – It reads the input or command and returns a string. input() – Reads the input and returns a python type like list, tuple, int, etc.

Is input a variable?

A variable is an input variable if its Input property is Yes. Its value can be input from an external source, such as an Architect call flow. A variable whose Output property is Yes is an output variable. When the script runs, any value assigned to the variable is saved for use outside of the script.


1 Answers

You can use string formatting to insert the value of x in the string:

sales = float(input("Please enter your sales from day {}".format(x)))

The current value of x will be inserted in the placeholder {}.

like image 167
Moses Koledoye Avatar answered Sep 18 '22 13:09

Moses Koledoye