投稿

2月 22, 2021の投稿を表示しています

generate cubes of numbers

#solution : generate cubes of numbers def cubicvar(): i=1 while True: yield i*i*i i +=1 print("cubes of number") for num in cubicvar(): if num> 1000: break print(num) ======= RESTART: C:/python/generateCubesOfNUmber.py ==== cubes of number 1 8 27 64 125 216 343 512 729 1000 >>>

calculate BMI by numpy array

Numpy arrays are great alternatives to Python Lists. Some of the key advantages of Numpy arrays are that they are fast, easy to work with, and give users the opportunity to perform calculations across entire arrays. In the following example, you will first create two Python lists. Then, you will import the numpy package and create numpy arrays out of the newly created lists. # Create 2 new lists height and weight height = [1.6, 1.87, 1.87, 1.82, 1.91] weight = [55.2,81.65, 97.52, 95.25, 92.98] print("height") print(height) print("weight") print(weight) # Import the numpy package as np import numpy as np # Create 2 numpy arrays from height and weight np_height = np.array(height) np_weight = np.array(weight) print("type") print(type(np_height)) # Calculate bmi bmi = np_weight / np_height ** 2 # Print the result print("BMI") print(bmi) # For a boolean response print("bmi > 23") print(bmi > 23) print("bmi 23]...