jeudi 16 septembre 2021

Generating random float number in Python

I just want to generate random float numbers between the range.But i am facing some issue This is my code

import xlsxwriter
import random

wb = xlsxwriter.Workbook('abc.xlsx')

ws = wb.add_worksheet()

start = input("Enter the start value:")
end = input("Enter the end value:")
ws.write('A1','InputRPM')

ws.write('A3',start)

row=3
col=0 

rand = [random.uniform(start,end) for i in range(20)]

rand.sort()

for i in rand:
  ws.write(row,col, i)
  row+=1

ws.write('A24',end)
wb.close()

Error:

Enter the start value:200
Enter the end value:300
Traceback (most recent call last):
  File "file.py", line 17, in <module>
    rand = [random.uniform(start,end) for i in range(20)]
  File "file.py", line 17, in <listcomp>
    rand = [random.uniform(start,end) for i in range(20)]
  File "/usr/lib/python3.8/random.py", line 417, in uniform
    return a + (b-a) * self.random()
TypeError: unsupported operand type(s) for -: 'str' and 'str'

I want to print generated float numbers in excel without using range in for loop.It will generate automatically once it reach the end value it stops the generating process.I am a new guy for this so i don't know the things.Can anyone help me to find this requirement.




Aucun commentaire:

Enregistrer un commentaire