random Decimal in python

后端 未结 7 1178
野趣味
野趣味 2020-12-31 08:24

How do I get a random decimal.Decimal instance? It appears that the random module only returns floats which are a pita to convert to Decimals.

7条回答
  •  一个人的身影
    2020-12-31 09:09

    import random
    y = eval(input("Enter the value of y for the range of random number : "))
    x = round(y*random.random(),2)  #only for 2 round off 
    print(x)
    

提交回复
热议问题