# -*- coding: utf-8 -*- """ Created on Mon Oct 3 10:59:41 2022 @author: cpresser """ #list list1 = [2, 5, 7] #tuples tuple1 = (3, 6, 8) tuple2 = 9, 0, 2 tuple1 = (7, 9, 10) list1[0] = 1 #tuple1[0] = 0 print(list1[0]) print(tuple1[0]) #functions # call the function len #use its result and call the function print print(len(list1)) list1.append(50) #method (function) #define our own functions # len(list1) # uses information: list1 argument or parameter # f(x) = 3*x # x: argument # f(5)= 3*5 = 15 #define a function def f(x): # function header: x is the argument # x is defined within the function return 4*x # return statement #call the function f with the argument 5 # print its return value print(f(5)) print(f(7)) for i in range(5): v = f(i) print(f"{i:5}{v:5}") #print(x) def speed(dist, time): s = dist/time return s print(speed(200, 4)) #assign the return value to a variable mySpeed = speed(200, 4) #200 becomes dist, 4 becomes time print(mySpeed) print(speed(4, 200)) #dist is 4, time is 200 #explicitly assign values to the parameters print(speed(time=4, dist=200), end=":)") def stars (n): result = "" i = 0 while i < n: #result = result + "*" result += "*" #i = i + 1 i += 1 #same as i = i + 1 return result def forStars (n): result = "" for i in range(n): result += "*" return result print(stars(10)) print(stars(30)) print(forStars(10)) print(forStars(30))