# we type our code in Pycharm, Pycharm hands our code to Python to run it # Python has to be brought up to run each program, making it an interpretive language # currently, there is only a programming section... # it may be in your interest to keep it that way # there will be partial credit. if you can't get things working, add comments saying what you were trying to do # give some documentation to your code even if you can get it working, it'll help if you fail a test # guiding comments like in homeworks? -> not sure if there will be these comments, but you will # be given a problem and general steps to follow. we'll talk about going from a written problem to code # today and in the review session # try to stay lined up with the comments for grading or bunch up the # algorithm at the top. something that is correct and follows the rules is correct, if infuriating # typically it is in your best interest to avoid infuriating the person grading your exam # Occam's Razor: the simplest solution is typically the best. you will not be expected to: # write 20 lines of code # nest for loops # access and process datasets from the web # WWAHD: what would a human do? - follow a human-ish algorithm, try to do it naturally # example test runs? yes. there will be possible program runs provided. test your code! there will be other # test cases, so make sure you can run multiple test cases # commenting policy: you don't have to comment. you can. commenting might increase your partial credit # if you can't put your problem solving into code, write it out in a comment. problem solving skills are # more important than the minutiae of your code # header comment with purpose will be provided # do what you are asked. do not print anything else # the test will not be curved. if it was, it would be curved down. median grade is B+, sometimes A- # don't worry about code efficiency. worry about getting the problems solved in the class period. # for the last problem, it can be done in 3 lines... don't stress yourself though average of ~6 lines # what resources will be available? # **you are expected to have a web browser open to the class site and pycharm open to test programs** # modules # info sheet # bring up pycharm and close alllllllllll the tabs IN PYCHARM. no programs should be open # the only programs that should be open in pycharm are the test programs # the test files will be available around 2 PM - names will be uncharacteristically ambiguous # test programs are subject to change # be honest please! # once you're done, submit each program the same way you submit the homework # different submission for each program # check that you've uploaded every single program. have a TA put eyes on it if you're nervous # if you have accomodations, you will be a-okay, when we call time we'll move to a different room # sorry that everything is weird with room bookings! # grading breakdown: each midterm will be about 1/3 of your grade, so do review # what can you do with rubber ducks? keep track on your tent card, they'll come up at the end of the semester # if you participate and earn ducks, you have a chance to have your grade rounded # style guidelines: good, descriptive variable names and padding spaces are expected and appreciated # don't use lowercase L as a variable # w can be word, x shouldn't be word # i,j can be counting variables # follow guidelines we've done in class if you're worried about variable names # if you want partial credit, again, good idea to follow the guidelines and make readable code # you will have the full class block to work on the exam. if you finish early, double check that you've # submitted all the programs and you will be free to leave, quietly (probably) # people will start leaving the room when they're done. don't stress it. take your time and make sure that # you're satisfied with all of your answers. the time it takes you does not factor into your grade at all # we will know if you use answers that you googled. use things we talked about in class # you have access to all of the documentation in the info sheet and modules page # seriously please don't cheat, it is not worth it and we want to continue to have fun here # homework solutions: we're on it, they will be posted tonight # can you print out the info sheet? no, then you might write on it, and that's sticky so just leave it on the web # focus on patterns from exam to exam more than specific questions # if python is mad at you, you've messed up. python tells you how. read the error message # can you... # use print() # use input() # do calculations (not from the math module, using the arithmetic operators we know + - * / // % # manipulate strings, lists # use accumulation - what kind (initalize to)? product ( = 1 )? total ( = 0 )? string ( = "" )? list ( = [] )? # you will be told what data type you should be building. please listen # ** ALWAYS define/initialize your accumulator outside of the for loop** # accum = 0 or 1 or "" or [] # for loop_variable in sequence : # accum = accum * new -- product # accum = accum + new -- total # accum = accum + new -- string # accum.append( new ) -- list **NEVER say accum = accum.append( new )** # use indices to access characters in strings/ elements in lists # sequence[ i ] # remember indexing starts at 0!! # go from element to the index: # strings: s.find( ch ) # lists: lst.index( element ) # use for loops # be careful this weekend! this covid thing is not a joke. please stay masked and safe, we'd like to # finish out the semester with y'all """ Purpose: code snippets from questions """ # random problem to solve: get a list of names from the user, make a list of properly capitalized names, # print the list of capitalized names and the first and last names alphabetically reply = input( "Enter names: ") names = reply.split() proper_names = [] for name in names : proper_name = name.capitalize() proper_names.append( proper_name ) sorted_names = sorted( proper_names ) # this is a built-in function that does not modify the original list # and hands back a new, sorted sequence. this is not testable! print( "proper names:", proper_names ) print( "sorted names:", sorted_names ) first_name = min( proper_names ) last_name = max( proper_names ) print( "first:", first_name ) print( "last:", last_name ) # the type() function is used in debugging. if something isn't working, check that what you think is a # list is actually a list and not a string, for example