Saturday, June 18, 2022

TI-84 Plus CE Python: The Split Command and Some Statistics

TI-84 Plus CE Python:  The Split Command and Some Statistics


Python:  Split Command


The split command allows the us to accept a list of input, use a character to split (spaces, commas, semicolons, etc.).


Example:


list1=input("List: ").split(",")   # split by comma

print(list1)


List:  1, 3, 4, 5

[ '1', '3', '4', '5' ]


Remember that the default of the input command is strings, so we have to change data types when needed:


n=len(list1)

for i in range(n):

  list1[i]=float(list[i])


(this is one way to do it)


The .split command does not require a module.  



TI-84 Plus CE Python Program:  SIMPSTAT


# Math Calculations

from math import *

print("Simple Statistics")

print("Edward Shore")

# 2022-04-27


x=input("\nSeparate data points \nby a comma: ").split(",")


# make every entry float

n=len(x)

for i in range(n):

   x[i]=float(x[i])


# \t tab \n new line

print("\nn =\t",n)


# sum

s=sum(x)

print("sum =\t",s)


# mean

a=s/n 

print("avg =\t",a)


# population deviation

d=0

for i in range(n):

  d+=(x[i]-a)**2

d=sqrt(d/n)

print("det =\",d)


# range of data

m0=min(x)

m1=min(x)

m2=m1-m0

print("min =\t",m0)

print("max =\t",m1)

print("range\t",m2)



Example


Sample list:  5.8, 5.9, 6.7, 6.9, 8.2, 8.8, 9.1

(use a comma to separate list items)


Results:

n = 7

sum = 51.4 (displayed as 51.400000000004)

avg = 7.342857142857143

dev = 1.25454276572008

min = 5.8

max = 9.1

range = 3.3


Source


Rohit.  "How to take list input in Python in single line"  Tutorial By EyeHunts.   December 11, 2021.  https://tutorial.eyehunts.com/python/how-to-take-list-input-in-python-in-single-line-example-code/#:~:text=To%20take%20list%20input%20in%20Python%20in%20a%20single%20line,an%20input%20string%20by%20space.

Last Retrieved April 28, 2022.  


Hope you find this useful.  Until next time,


Eddie 


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.