python3 int(input())

Asked 1 years ago, Updated 1 years ago, 103 views

import random
x=random.randint(1,100)
y=random.randint(1,100)
z=x-y
a=int(input(x, '-',y, '='))
if a==z:
    print()' is correct.')
else:
    print ('wrong')

I'm learning Python basics. I wrote the code above, but I keep getting errors in the input part. How should I fix it?

Goal is

Create a program that outputs x-y= (show the problem) and receives the user's answer as input, stores it in a, and checks if it is correct by creating a pixel expression with random numbers x and y.

python-3.x

2022-09-21 21:16

1 Answers

Read the official document.

https://docs.python.org/ko/3/library/functions.html#input

When you ask an error question, you must specify an error message.

TypeError                                 Traceback (most recent call last)
<ipython-input-1-1461bcef0751> in <module>
      3 y=random.randint(1,100)
      4 z=x-y
----> 5 a=int(input(x, '-',y, '='))
      6 if a==z:
      7print('Correct.')

TypeError: input expected at most 1 arguments, got 4

The input function requires only one factor, but it is a message that 4 factors are included.

a=int(input(f'{x} - {y} = '))

As mentioned above, the factors within the input must be treated as one string.


2022-09-21 21:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.