小编Pet*_*lan的帖子

使用isdigit浮动?

a = raw_input('How much is 1 share in that company? ')

while not a.isdigit():
    print("You need to write a number!\n")
    a = raw_input('How much is 1 share in that company? ')
Run Code Online (Sandbox Code Playgroud)

这仅在用户输入时才有效integer,但我希望即使他们输入了一个,但我希望它能够工作float,而不是在他们输入时string.

因此,用户应该能够同时输入99.2,但不会abc.

我该怎么办?

python parsing user-input

26
推荐指数
5
解决办法
4万
查看次数

标签 统计

parsing ×1

python ×1

user-input ×1