*specified except specifies exactly what the error is. this is handy because there can be many errors in a code. this way each error is accounted for and has a different outcome for each
*examples are except ZeroDivision: and except ValueError:
day 14 of #100daysofcode
*.islower() confirms whether the parameter contains characters in lowercase
*isupper() confirms whether the parameter contains characters in lowercase
*commenting: put # in comments
*try except block: protects the program. |
* try (code_)
*except: notifies the user (the person making the input) that the input is wrong/makes the code not compile due to error by printing a sentence notifying them of it.
*there are many types of specified except variations
* we used for loop because it starts from 0 unil the number of elements in phrase (the input) -1.
*checking if a part of variable is in a set of string:
if variable_name in set_of_string
*return translation means if they call translate and give us input, we give them translation
day 13 of #100daysofcode. apparently i did day 1o twice.
*2d list:
list_name=
[1,2,3],
[4,5,6],
[7,8,9],
[0]
for row in list_name:
print(row)
that prints out the list as a whole
print (translate(input("enter a phrase")))
*making a function named translate that receives a parmeter and names it(of the type) "phrase". making a string variable named translation which will be the final output of this function.
#100daysofcode (102 days)day 11:
*making a better "power of" code than A**B using for loop
def raise_to_power(base_num, power_num):
result=1
for index in range(pow_num)
//what the code above means the loop runs as much as power_num (which is the second parameter)
*result=1 because running it for the first time gives the original number (power of 1). if you dont do this the first result, *this is a better code because the code adjusts based on input and not on what it initially wasower of 1, is squared
#100daysofcode day 10
*while loop: while *insert_condition_here* :
action
*incrementing a variable: variable +=(how much increment)
*using for loops to go through elements in an array:
array_sample=[]
for variable_name in array_sample:
print(variable_name)
*getting length of arrays: len(variable_name)
*range() is a function that gets a number ranging from 0 until the limit of that number-1. this number can also be derived, for example using len() function.
*in python making a for loop is different
#100DaysOfCode day 10.
* repeated the tutorial and found out i missed something. you have to put "return" right before ending your function. that's what makes it "return function"
*return skips right to the code that called it. code after return is redundant
*dictionaries: special structure in python. allows storing key-value-pairs
*making dictionaries: dictionary_name = {valueA:valueB}
where value B is the associated value to A
*invoking dictionaries: dictionary_name["either valueA or valueB"]