write a program to generate a series a float numbers from 21.0 to 30.0 with an increment of 1.5 each
Answers
Explanation:
import pandas as pd
import numpy as np
def fl_ser():
n = np.arange(21,32,1.5)
s = pd.Series(n)
print(s)
fl_ser()
Python program that generates a series of floating-point numbers from 21.0 to 30.0 with an increment of 1.5 each:
start = 21.0
stop = 30.0
step = 1.5
numbers = []
current_num = start
while current_num <= stop:
numbers.append(current_num)
current_num += step
print(numbers)
This program uses a while loop to iterate over the range of numbers and adds each one to a list. The loop continues until the current number is greater than the stopping point. Finally, the list of numbers is printed to the console.
In summary, the program does the following:
- Sets the starting point, stopping point, and step size as variables.
- Initializes an empty list to store the generated numbers.
- Starts a loop that continues until the current number exceeds the stopping point.
- In each iteration of the loop, adds the current number to the list and increments it by the step size.
- Prints the list of generated numbers to the console.
To learn more about while loop from the given link.
https://brainly.in/question/9705104
#SPJ3