1

I know this is incorrect because 'input()' can only take 1 argument, but I want to include these variables in the input while asking the user to enter more numbers:

n = 5
average = 0
for i in range(n):
    numbers = eval(input('Please enter number ', (i+1) ,' of ', n ,' to average:',sep='',end=''))
    average = average+numbers/n
1
  • 5
    input isn't like print, it takes a single string to show as the prompt. You have to create that string yourself - Python has several options for string formatting you could do some research on. Also you should almost never use eval. Commented Oct 14, 2018 at 21:34

2 Answers 2

2

You can use string formatting and F-Strings ( only Python 3.6+ )

String Formatting:

n = 5
average = 0
for i in range(n):
    numbers = int(input('Please enter number {} of {} to average:'.format(i+1, n)))
    average = average+numbers/n

F-Strings (Works in Python 3.6+):

n = 5
average = 0
for i in range(n):
    numbers = int(input(f'Please enter number {i+1} of {n} to average:'))
    average = average+numbers/n
Sign up to request clarification or add additional context in comments.

Comments

0

You could try concatenating your variables after converting them to string [str(x)]

n = 5
average = 0
for i in range(n):
    numbers = eval(input('Please enter number '+str(i+1)+' of '+str(n)+' to average:'))
    average = average+numbers/n

This is a naive approach but works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.