#functions.py #demo some functions #print() here takes one string argument. Returns None. print("hello world") #input() takes a string argument. Returns a string. s = input("Enter stuff: ") print(s) #len() takes a string [or list] argument. Returns an int length_s = len(s) print(length_s) #min() takes any number of arguments, either all numeric or all string, [or a list] min_int = min(34,56,23,67,12,456,24) print(min_int) min_string = min("asdf","qwerty","tyurtyu","aavcdf","hello") #asciibetical min print(min_string) #type() takes any argument, returns its type. Here for learning purposes. print(type(1234)) print(type(1234.56)) print(type("asdfasdf")) a = 1234 b = 1234.56 c = "asdfasdf" print(type(a)) print(type(b)) print(type(c)) #quit() terminates the program. Choose Cancel else Shell terminates too. ans = input("Do you want to quit? (y or n): ") if ans.upper() == 'Y': quit() # type conversion functions #int() takes an int-looking string argument, returns an int of it i = int("1234") print(type(i), i) #int() can take a float argument and return the truncated integer part of it print(int(3.99)) #round() will round a float argument up or down print(round(3.5)) print(round(3.49)) #float() takes a float-looking string argument, returns a float of it f = float("1234.45") print(type(f), f) #str() takes a number argument, returns a string of it s1 = str(1234) print(type(s1),s1) x = 456.56 print("Your number is " + str(x)) import math #math.sqrt() takes a number argument, returns a float print(math.sqrt(25)) print(math.sqrt(2)) print(math.sqrt(math.pi)) import random #random.random() takes no argument, returns a random float between 0 and 1 print(random.random()) print(random.random()) print(random.random()*100) # [0,100) print(random.random()*100)