My First App

Run Settings
LanguagePython
Language Version
Run Command
# fundatmental DataTypes print( type(2 + 4)) print( type(2 - 4)) print( type(2 * 4)) print( type(2 / 4)) # 0.5 print(type(9.9 + 1.1)) # 11.0 print( 2 ** 5) #to the power of print( 9 // 4) #divison but with rounding automatically print ( 6 % 4) # remainder # math functions print(round(3.5)) print (abs(-20)) print ((20 -3 ) + 2 ** 2) #PEMDAS print(bin(12345)) print(int('0b101', 2)) user_iq = 190 user_age = user_iq/4 print(user_age) #Constants PI = 3.14 # never meant to change ..you can but shouldnt #double unscores dont not otuch them a,b,c = 1, 2, 3 print(a) print(b) print(c) iq = 100 age = iq/5 print(age) #augmented assignment operator some_value = 5 some_value += 2 print(some_value) #Strings 'hello' print(type ("Hello there")) username = "coder" password = 'coderpass' long_string = ''' WOW this is now ''' print(long_string) first_name = 'Avery' last_name = 'Gaskins' full_name = first_name +' ' +last_name print(full_name) # String concatenation print('hello' + ' Avery') print('hello' + ' Avery') print(type(str(100))) #Type conversion a = str(100) #Escape Sequence weather = "\t It's \"kind of\" sunny \n\t hope you have a good day" print(weather) #fromatted strings name = 'Johnny' age = 55 print(f'hi ' + name + '. age: ' + str(age)) print(f'hi {name}. age: {age}') # [start:stop:stepover] selfish = '01234567' print(selfish[0:8:3]) print(selfish[1:]) print(selfish[:5]) print(selfish[::1]) print(selfish[-1]) # Start at the end of the string print(selfish[::-1]) # list the string backwards #Immutability - they cannot be changed #selfish [0] = 8 # cannot resassing within the string selfish = selfish + '8' # you have to change the whole string and create somthing new print(selfish) qoute = 'to be or not to be' print(qoute.capitalize()) print(qoute.find('be')) print(qoute.upper()) print(qoute.replace('be', 'me').capitalize()) print(qoute) #boolean name = 'Avery' is_cool = False is_cool = True print(is_cool) print(bool(1)) print(bool('True')) name = 'Avery Gaskins' age = 32 relationship_status = 'married' print(relationship_status) #your answer #current_year = 2025 #birth_year = input('What year were you born?') #user_calulated_age = current_year - int(birth_year) #print(f' \nYou are {user_calulated_age} years old'); #comments #username = input('enter username') #password = input('enter password') #password_length = len(password) #hidden_password = '*' * password_length #print(f'{username}, your password {hidden_password} is {password_length} long') #List slicing amazon_cart = [ 'notebooks', 'sunglasses', 'things', 'toys', 'etc' ] li2 = ['a','b','c'] li3 = [1,2,'a', True] #acccessing list print(amazon_cart[0]) print(amazon_cart[0::2]) amazon_cart[0] = 'laptop' new_cart= amazon_cart[:] new_cart[0] = 'gum' print(new_cart) print(amazon_cart) #Matrix matrix = [ [1,2,3], [2,4,6], [7,8,9] ] print(matrix[0][1]) print(matrix[2][2]) basket = [1,2,3,4,5] #adding #appending # extnd #new_list = basket.append(100) #new_list = basket.insert(4,100) #new_list = basket.extend([100,101]) new_list = basket print(basket) print(new_list) #removing basket.pop() basket.pop(0) # removes from index point basket.remove(2) # removes from actually number or object in array new_list = basket.remove(4) new_list = basket.clear() print(basket) basket2 = ['a','b','c','d','e','d'] print('d' in basket2) print('i' in 'him my name is avery') print(basket2.index('d', 0 , 4)) print(basket2.count('d')) basket2.sort() basket2.reverse() #print(basket2[::-1]) #print(basket2) print(list(range(1,100))) new_sentence= ' '.join(['hi', 'my', 'name', 'is', 'JOJO']) print(new_sentence) #list unpacking a,b,c, *other, d = [1,2,3,4,5,6,7,8,9] print(other) print(d) weapons = None print(weapons) #dictionary dictionary = { 'a':[1,2,3], 'b':'hello', 'c': True } print(dictionary['b']) print(dictionary['a'][1]) my_list = { 'a':[1,2,3], 'b':'hello', 'c': True }, { 'a':[4,5,6], 'b':'goodbye', 'c': False }, print(my_list[0]['a'][2]) #List has order my_list2 = { 'basket':[1,2,3], 'greet':'hello', 'age': 20 } print('basket' in my_list2) print('size' in my_list2) print('hello' in my_list2.values()) print player2 = my_list2.copy() #my_list2.clear() print(my_list2.pop('age')) print(my_list2.update({'age':55})) print(my_list2.update({'ages':55})) print(player2) print(my_list2) print(my_list2.get('age', 55)) #method 2 of creating dictionaries user2 = dict(name = 'JohnJohn') print(user2) #Tuple my_tuple = (1,2,3,4,5) #my_tuple[1] = 'z' print(my_tuple[1]) print(5 in my_tuple) user_tuple = { (1,2) : [1,2,3], 'greet': 'hello', 'age' : 20 } print(user_tuple[(1,2)]) my_tuple2 = (1,2,3,4,5,5) x = my_tuple2[0] y = my_tuple2[1] x,y,z, *other = (1,2,3,4,5) print(z) print(my_tuple2.count(5)) print(my_tuple2.index(5)) print(len(my_tuple2)) my_set = {1,2,3,4,5,5} my_set.add(100) print(my_set) #everything needs to be unique my_list = [1,2,3,4,5,5] print(set(my_list)) my_set = {1,2,3,4,5,5} new_set = my_set.copy() print(len(my_set)) # only counts uniqu print(list(my_list)) # converst to list my_set3 = {1,2,3,4,5} your_set = {4,5,6,7,8,9,10} #print(my_set3.difference(your_set)) #print(my_set3.discard(5)) #print(my_set3) #print(my_set.difference_update(your_set)) #print(my_set) #print(my_set.intersection(your_set)) #print(my_set.isdisjoint(your_set)) # False - these sets have nothing in common , True these sets have something in common print(my_set.issubset(your_set)) print(my_set.issuperset(your_set)) #Conditinal Logic is_old = False is_licensed = True if is_old and is_licensed: print('you are old enough to drive, and you have a license!') else: print('you are not old enough') print('out of loop') #Truty and Falsy #Truthy print(bool('hello')) print(bool(0)) #Falsy print(bool('')) print(bool(0)) #method 2 condtionals : Ternanry # conditio_if_true if condtion else condition_if_else is_friend = True can_message = "message allowed" if is_friend else "not allowed to message" print(can_message) #short circuiting is_friend2 = True is_user= True if is_friend2 or is_user: print('best friends forever') #Other logical operators < = > <= >= not and or print(not(True)) #Excercise #3 is_magician = True is_expert = False # check if mage AND expert: "you are a master mage # check if mage but not expoer : at leasst your getting ther # check if youre not a mage : well you need magic powers if is_magician and is_expert: print('you are a master mage!') elif is_magician and not(is_expert): print('at least your getting there') else: print('you need magic powers') #Forloops user = { 'name': 'Golem', 'age': 5006, 'can_swim': False } for item in user.items(): print(item) for key, value in user.items(): print(key, value) #excercise 4 my_list5 = [1,2,3,4,5,6,7,8,9,10] product = 0 for item in my_list5: print(f' {product} + {item}') product += item print(f' items count is {product}') for item in user.values(): print(item) for item in user.keys(): print(item) for item in [1,2,3,4,5]: for x in ['a','b','c']: print(item, x) print('for loop is over') #iterable - collection that can be iterated over (list , yuple , set , string,dictionary) #range print(range(100)) for item in range(0,10): print(f' email {item} to user') for _ in range(2,0,-1): print(list(range(10))) #enumerate for i,char in enumerate('Hellooooo'): print(i,char) for i,char in enumerate([1,2,3]): print(i,char) for i,char in enumerate(list(range(100))): if char == 50: print(f' the index of {char} is {i}') #while loop i = 0 while i < 50: print(i) i += 1 #break else: print('exit while loop') #For loop ad while loop comparison my_list = [1,2,3] for item in my_list: continue print(item) i =0 while i < len(my_list): print(my_list[i]) i += 1 #while True: will allow the user to say anything unil the user say bye and then loop breaks # response = input('say somthing: ') # if (response == 'bye'): # break #Excercis! picture = [ [0,0,0,1,0,0,0], [0,0,1,1,1,0,0], [0,1,1,1,1,1,0], [1,1,1,1,1,1,1], [0,0,0,1,0,0,0], [0,0,0,1,0,0,0] ] for row in picture: for pixel in row: if (pixel == 1): print('*', end='') else: print(' ', end='') print('') # need new line after every row #Excercise check for duplicates some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n' ] new_list = [] for item in some_list: if some_list.count(item) > 1: if item not in new_list: new_list.append(item) print(new_list) #functions # Postional Parameters vs arguments # Default parmetes #return def say_hello(name='JohnSmith', emoji='noting'): print(f'Helllloo, {name} {emoji}') #arguments - actualy valus we provide to a functions say_hello('Avery', ':)') say_hello() # Parameters vs arguments #def sum(num1, num2): # def another_func(num1,num2): # return num1 + num2 # return another_func(num1,num2) #total = sum(10,5) #print(total) #methods and fucntions def test(a): ''' Info: this fucntion test and prints param A ''' print(a) test('!!!!') help(test) print(test.__doc__) #cleancode #def is_even(num): # if num % 2 == 0: # return True # elif num % 2 !=0: # return False #print(is_even(51)) def is_even(num): return num % 2 == 0 print(is_even(51)) def super_func(name, *args, i='hi', **kwargs): print(kwargs) total = 0 for items in kwargs.values(): total += items return sum(args) + total print(super_func('Andy', 1,2,3,4,5, num1=5, num2=10)) #Rule: params, *args, default paramets, **kwargs numbersSample = [1,2,3,4,10,24,5,78,35] def highest_even(numbers): evenNums = [] currentNum = 0 passNum = 0 for items in numbers: if items % 2 == 0: evenNums.append(items) for highest in evenNums: currentNum = highest if currentNum > passNum: passNum = currentNum return passNum print( highest_even([1,2,3,4,10,24,5,78,220,100,35])) #Data Structure - way for us to organize information and date into a structure that can be used
#operator precedences
Editor Settings
Theme
Key bindings
Full width
Lines