guessNum = int(input("guess the number between", minNum, "and",maxNum))でのエラー

Asked 1 years ago, Updated 1 years ago, 381 views

I couldn't solve it myself while studying, so I'd like to ask you a question.
I enter the minimum and maximum values and write a code to guess the randomly selected number, but I get an error on the last line.

If you use print, you will see no errors, but if you use int(input), you will see an error.What is the difference?
I would appreciate it if you could tell me.Thank you in advance.

import random 
minNum = int(input("what is the minimum number for the range")) 
maxNum = int(input("what is the max number for the range"))
prob = random.randrange(minNum + 1, maxNum + 1) 
guessNum = int(input("guess the number between", minNum, "and",maxNum))

python

2023-04-19 09:04

1 Answers

If you have any doubts, I recommend that you read the document carefully.
Then why don't you ask questions when you don't know where the cue is?
(In that case, you'd better write it down.)

組み込み関数 より

input()
input(prompt)

If the argument prompt exists, it is written to standard output except for the last line feed.This function then reads a line from the input, converts it into a string, and returns it (except for the last line feed). EOF が読み込まれたとき、 EOFError が送出されます。

print(*objects, sep=' ', end='\n', file=None, flush=False)

Displays objects in the text stream file, separated by sep, and finally displays end.If you give sep, end, file, flush, you must give it as a keyword argument.

print() allows you to specify multiple objects
For input() prompt Only one (at most) can be specified

>>> print(12, 345, 12+345)
12 345 357
>>> print(12, 345, 12+345, sep=', ', end='# comma separated\n')
12, 345, 357# comma separated
>>> print(f'12 + 345 = {12+345}')
12 + 345 = 357
>>>
>>> input('Please enter'')
Please enter 10
'10'
>>> input('Please enter', 'Up to 10')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: input expected at most 1 argument, got 2
>>>


2023-04-19 12:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.