Forum Posts

Bonnie Ma
Jan 10, 2022
In Python for ACSL
0
0
4
Bonnie Ma
Dec 12, 2021
In Python for ACSL
Problems: Summary of concepts: https://www.lol-101.com/classrooms/python-for-acsl/all-concepts-master-review-sheet
0
0
4
Bonnie Ma
Dec 05, 2021
In Python for ACSL
This week's problems: https://docs.google.com/document/d/1FVY49XwN7f3UsEiYSroMUWh90IiRJoQFavjn7m3vdMU/edit
0
0
7
Bonnie Ma
Nov 14, 2021
In Python for ACSL
Slides: https://docs.google.com/presentation/d/14py7D84u97TV8cydoxRSmYG8LlqLPeUAwSJbt6K1M-E/edit?usp=sharing Homework: https://docs.google.com/document/d/1NkCePUdAqxIhn5H7Z6DkoowlvwW2nSldhcDtE_oAexM/edit?usp=sharing
1
0
12
Bonnie Ma
Nov 07, 2021
In Python for ACSL
Slides: https://docs.google.com/presentation/d/1g9MdWoEB1vhY8tMRy1GgM-hOZHYYArEZNoCwmKO_KIU/edit?usp=sharing No homework this week!
0
0
4
Bonnie Ma
Nov 06, 2021
In Python for ACSL
Slides: https://docs.google.com/presentation/d/1SpO5UwSTMBqb2KzQcmNSrohlx6QLpvdTKFqQX5rjaoc/edit?usp=sharing Homework (Questions 6 and 8, 9 optional): https://docs.google.com/document/d/1DYn1g4Zv_aLu7cUJ0u5dxy1QS7Mpyu6kwuk17tvoAug/edit?usp=sharing Reach out if you have questions. -Bonnie
0
0
9
Bonnie Ma
Oct 30, 2021
In Python for ACSL
Hey, everyone. Hope the homework this week went well. Reach out if you have questions! The code files are linked to the images if you want to take a closer look. -Bonnie Question 3: Question 6: See you all tomorrow. Ask us any questions you have! -Bonnie
Class 7 Homework Solutions content media
0
0
5
Bonnie Ma
Oct 24, 2021
In Python for ACSL
Question 7 - Given a string S, print the length of the longest substring with no repeated characters. last line: print(maxLength) **Optimizations: Line 6 A substring can only be max 26 letters long where every letter appears once - adding this min() shortens the number of iterations the program needs to do, 'cause if the substring is longer than 26 there is no way every character can be unique (Other optimizations exist, but are more complicated) Question 9 - Given a string S, print the character that appears the most in S. Line 8 - max count will always be highest for the first occurrence of a character, so we start from i instead of zero
Class 6 - Homework Solutions content media
0
0
6
Bonnie Ma
Oct 24, 2021
In Python for ACSL
Hi, everyone, welcome back - I'm getting busier with school and whatnot nowadays and can't spend as much time writing these lesson notes, so I'll leave them kind of barren for now and so just reach out to me if you need specifications -Bonnie While Review Homework Review Lists Homework - Questions 3 and 6 *Need to use list methods like .append() (adding to the end of list), .insert() (adding to a specific location of list), .pop() (removes from list), .sort() (sorts list by smallest to largest) REVIEW OF WHILE LOOPS LISTS Indices - lists are a collection of variables in a single "basket" - each can be changed individually by referencing their location in the list (index) and is their own complete variable, acts like any other regular variable. list = ["abc", "def", "ghi", 12, 5] 0 1 2 3 4 ^Lists use square brackets [] and are given a name and a value (declared/instantiated) just like other variables, with the name and then an equal sign ^Indices are assigned starting from 0, increase 1 each time print(list[1]) sum = list[3] + list[4] print(list[0]) print(list[2 - 1]) list[1] = "hi" print(sum) ----------------- --------------------- print(list[1]) ----------------------------- "abc" "def" --------------------- 17 "def" "hi" list.split(separator) - separates a string into a list, separated by spaces by default but you can choose any character message = "hello my name is Bonnie" message = "3.12313.eoiwjf.129" message.split() message.split(".") print(message) print(message) ---------------------------------------- ------------------------------------------------ ["hello", "my", "name", "is", "Bonnie"] ["3", "12313", "eoiwjf", "129"] Ask me any questions any time See you guys next week :) -Bonnie (and Alan)
Class 7 - Lists content media
0
0
15
Bonnie Ma
Oct 17, 2021
In Python for ACSL
Hi, everyone, here's what we did this week: Homework Review While Loops New Homework - Questions 7 and 9 Question 5 homework solution from last class: While Loops A different type of loop. For loops run on an iterable, and while loops run on a condition. Think of it as a loop with a built-in if statement. Every iteration of the loop, the given condition will be checked to make sure it's still True. If it has become False between the beginning of this loop and the last time it was checked at the beginning of the last loop, then the loop will terminate. The danger with while loops is that they will run forever. Make sure you are continuously updating the condition so that you don't create an infinite loop. An infinite loop looks like this: a = 0 while True: while a < 10: print("hello") print(a) ^There is nothing in the loops' bodies to change the condition. These loops will run forever. A proper while loop looks like this: a = 0 while a < 10: print(a) a += 1 ^ the variable a is being incremented each repetition of the loop, so you know eventually it will reach 10, make the condition False, and stop the loop. Well, this proper while loop kind of looks like something that could be done easier with a for loop. You're right - while loops are usually not used like this, since for loops can iterate a set number of times so much easier. Here is a for loop that does the same as that while loop: for I in range(10): print(I) ^Here we also iterate 10 times but we don't have to manually declare and increment a variable like we needed to for the while loop. While loops are more useful for when you don't know how many times you will need to repeat a section of code. You just know what you need to stop at, so make that your condition. Thanks, everyone. Reach out if you have questions! -Bonnie
Class 6 - While Loops content media
1
0
20
Bonnie Ma
Oct 10, 2021
In Python for ACSL
Welcome back, everyone. This week's homework and the problems we did in class were a little challenging, but I hope you all tried the problems or to follow along. Please don't be discouraged if you weren't able to figure it out on your own at first - programming and logic take time to learn and we cover the necessary fundamental concepts quite fast. Read the lesson notes or ask for us to go over something again in class to make sure you can keep up. I'm available through Discord (bonnie#7837, or through the server) and email (bonnie.ma200@gmail.com) as well :) -Bonnie 1:00-1:10 -> For Loop Review 1:10-1:26 -> Homework Review (Questions 6 and 7) 1:26-1:34 -> Nested For Loops (Question 8) 1:34-1:40 -> Scope 1:50-2:30 -> Nested loop problems · Question 1 · Question 2 · Question 3 · Question 4 HOMEWORK - QUESTIONS 5 AND 6 (solutions will be posted Saturday night) NESTED FOR LOOPS CLASS PROBLEMS - QUESTION 1 CLASS PROBLEMS - QUESTION 3 CLASS PROBLEMS - QUESTION 4 Thanks, guys! See you all next week :) -Bonnie (and Alan)
Class 5 - Nested For Loops content media
1
0
15
Bonnie Ma
Oct 09, 2021
In Python for ACSL
Hi, everyone! Homework this week was Questions 6 and 7 from this doc. Links to the code are linked to the images. Hope you all did your homework haha Given 2 integers N and M, print out the first M multiples of N. Given an integer N, print out the first N Fibonacci numbers. Bring any questions you guys have with you to class tomorrow. See you all soon. -Bonnie
Class 4 - Homework Solutions content media
1
0
10
Bonnie Ma
Oct 03, 2021
In Python for ACSL
Hi, everyone! I'm a bit busy this week so lesson notes are gonna be briefer. Reach out for more detailed explanations if you need them, though. -Bonnie Review: Boolean expressions, Boolean operators, if statements, comparison operators For Loops: Syntax, nested for loops Class Problems/Homework - Questions 6-7 (7 is hard, if it's too hard wait until the solutions come out on Saturday night or ask for help) FOR LOOPS range() is a built-in function in Python that creates a list in increasing order based off of three parameters: start, stop, and skip. By default, start is 0, and skip is 1. Start is the number you want the list to start from. Stop is the number that the list will stop right before reaching it. Skip is the interval you want the list to increase by (it can be negative for decreasing order). print(range(10)) ---------------------- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ^Why does the number I give for the stop parameter never included in the list? Count the numbers in that list. Since in programming we use 0 to refer to the first item in a list, starting from 0 and counting to 9 creates the 10 item list that you requested. Using range(num) creates a list of len() = num. NESTED FOR LOOPS (not covered in class yet, read only if you want) Nested for loops are loops inside loops. Each iteration of the outside loop will make its nested loop run completely each time. for i in range(10): for j in range(10): print("hello") ^ In this example, "hello" will be printed 100 times. ^ Also, the variables you initialize to iterate through nested loops can't be the same. Across separate loops it's fine. But nested loops are connected and the program will get confused if you use duplicate variable names. That's all, folks. See ya -Bonnie (and Alan)
Class 4 - Back for More content media
1
0
11
Bonnie Ma
Oct 03, 2021
In Python for ACSL
(Click the images for the full file) Question 6 Question 7
Class 3 - Homework Solutions content media
0
2
13
Bonnie Ma
Sep 26, 2021
In Python for ACSL
Contact Information: Bonnie Ma Alan Xiao Teacher's Assistant (TA) Teacher bonnie.ma200@gmail.com alanxiao211@gmail.com bonnie#7837 on Discord Class 1 PEMDAS (not including modulus or roots) Class 2 Modulus and roots Variables User input Typecasting (int(), str(), etc) Class 3 Boolean expressions (and, or) If/Elif/Else statements Comparison operators (>, <, etc) Class 4 For loops Range() Class 5 Fibonacci numbers Nested For loops Scope Class 6 While loops Class 7 Lists - "baskets of variables" Class 8 Functions Class 9 File Input REVIEW FOR ACSL Class 10, Class 11, Class 12
2
2
48
Bonnie Ma
Sep 26, 2021
In Python for ACSL
Welcome back, everyone. -Bonnie 1-1:17 -> Review (check Post 2 for details) 1:17-1:23 -> Review Quiz 1:23-1 -> Boolean Expressions* 1:28-1:31 -> If Statements 1:31-1:34 -> Else Statements 1:34-136 -> Elif Statements 1:36-1:40 -> Comparison Operators 1:50-1:58 -> Sample Problem 1:58-2:30 -> Individual Practice HOMEWORK - 6 and 7 *Today's class was recorded, starting from Boolean expressions. REVIEW QUIZ Integer (Floor is used, so there are no floats in this expression, only whole numbers) Boolean (Booleans are True or False) String (Denoted by "") Float (Numbers with decimals) BOOLEAN EXPRESSIONS An expression is a combination of values and operations in a program. They can be of any data type. 1 + 2 * 3 is an expression with value 7. A boolean expression is just an expression that evaluates to a boolean. There are special operators we use for this called logical operators - and two that we will introduce now are "and" and "or". In Python, we just write the words "and" and "or" directly into our code. In other languages, you might have to use specific symbols. AND is an operator that compares two clauses. If both clauses are true, it will return True. If one of both are false, it will return False. print(1 * 10 == 10 and 2 == 2) print(10 == 1 and 10 == 10) print(1 == 2 and 1 == 3) ----------------------------------- ----------------------------------- ------------------------------ True False False OR is an operator that also compares two clauses, but it is more inclusive than and. If at least one clause is true, it will return True. Only when both are false will it return False. (So of course is both are true, it returns True.) print(1 * 10 == 10 and 2 == 2) print(10 == 1 and 10 == 10) print(1 == 2 and 1 == 3) ----------------------------------- ----------------------------------- ------------------------------ True True False IF STATEMENTS If is a keyword that runs some code if a given condition is met. This condition is where we often use the logical operators we covered above. if (condition): code If the condition is not met, then the code inside the if statement will not run, and the program will just continue on to the code under the if statement. Code inside the if statement needs to be specially formatted so that the program understands it belongs to the if statement - we use indents for this. Press TAB on your keyboard at the beginning of a single line or highlight all the lines you want indented and hit TAB to indent your work. If you've indented too far, highlight the code and press Shift+TAB to reverse indent your code. ELSE STATEMENTS Else is a keyword similar to If. Else statements are attached to if statements and will run if the condition in the if statement is not met. It will only run as the very last resort in any chain of if/elif statements and will be canceled if any of the statements before it run. if False: code A else: code B ^ In this pseudocode (summarized, simplified version of real code), the condition in the if statement equates to False, so Code A will not run. The program will then default to an else statement, if there is one, and since there is one, Code B will run. ELSE IF (ELIF) STATEMENTS Elif is the final piece to the if statement trifecta. Elif stands for Else If, but Python has just abbreviated it. Else if statements run if the if statements and the other else if statements before it have conditions that are not met. In terms of priority, the program will first check the if statement, then the else if statements in the order they are written, then the else statement. if False: code A elif False: code B elif True: code C -> after running Code C, the program exits this block of if statements and continues on to the rest of the program. else: -> skipped code D -> skipped ^ In this example, as the if and first elif statements are unable to run, Code C is executed. This means the else statement is not run. if True: code A elif True: code B else: code C ^In this example, while the elif statement has its condition met, it will not run, as the if statement has priority. The else statement also does not run. So in this example, only Code A is run. COMPARISON OPERATORS == - equals < - less than > - greater than <= - less than or equal to >= - greater than or equal to We can use these operators in if statements to determine if some conditions are met. PRACTICE PROBLEM ^ The order of the conditions doesn't matter - as long as you are using one if, one elif, and one else statement, you are all good. INDIVIDUAL WORK TIME Q1 - Given an integer A, check if it is odd or even. If A is odd, print “odd”, and print “even” if it is even. (We did this question in class together.) ^ The % modulus operator (mod for short) was covered in Class 1. It is a division operation that returns the remainder of the division rather than the standard quotient. (So 16 % 4 is 0.) Q4 - Given 2 integers A and B, check if the product of A and B is even without multiplying them. If it is, print "Yes", else, print "No". ^ If at least one of the two integers is even, their product will be even. This is basically a math question - you just needed to notice that this was true. We can use modulus to determine whether the numbers are odd or even.
Class 3 - If Statements and Boolean Expressions content media
1
2
30
Bonnie Ma
Sep 26, 2021
In Python for ACSL
Good evening, guys! Hope I'm not coming at you with these solutions too late. Take a second to review your answers and prepare some questions to ask in class. Or ask them whenever you want on Discord or through email. (Yes, I say that a lot, but I just want people who haven't noticed yet to know I am free to answer questions whenever.) Good work on completing this week's homework - if you haven't, take the time right now to do it, before reading the answers. It will feel better than just copying the answers. Homework solutions in the future will all be posted like this, with the question and a screenshot of my work. The repl with the work is linked to the image. I don't know how to remove editing permissions, so just please don't edit the files at all. Each question is in its own repl. Lemme know if there are any issues. 6. Declare one integer A and without using the square root function, find sqrt(a). 7. Given some temperature F in Fahrenheit, convert it to Celsius. 8. Given some mass M in kilograms, convert it to grams Good work, everyone. -Bonnie
Class 2 - Homework Solutions content media
1
0
9
Bonnie Ma
Sep 19, 2021
In Python for ACSL
Welcome back, everyone. Or for those who weren't here last week, welcome! You can review the Class 1 post I made to catch up on what you missed. Glad to "see" all of you here this week :) If a lot of what was covered this week was new information, and it was hard to keep up, don't worry. A lot of fundamental topics were covered this week and I imagine if you haven't heard of them before it must be overwhelming. Take your time reviewing these lesson notes - I'm gonna try to write them in detail, and as always, reach Alan or me through email or Discord if you need more help. I'm available most of the time, but I am in a different time zone (EST) so I'm 3 hours ahead of you guys in PST. Just keep this in mind - but I will always answer within 24h (at the very most). -Bonnie 10-10:10 -> Review from last class; check previous post for details 10:10-10:16 -> New arithmetic syntax 10:16-10:23 -> Review questions 10:23-10:40 -> Variables 10:50-11:04 -> Variable Activity 11:04-11:? -> User input and Typecasting 11:?-11:30 -> Some of the homework HOMEWORK (Questions 6-8) - https://bit.ly/3AnYjCE (more info) 9/25 - HOMEWORK SOLUTIONS ARE UP ABOUT IDES - Feel free to use whatever IDE you like. Visual Studio Code, repl.it, anything is fine. Ideone.com is just Alan's suggestion. If anyone would like specific help with homework in the future, we will probably use repl.it (it's like Google Docs for code) and it's easy to use - feel free to familiarize yourself with it in advance anyways if you feel like it. Repl.it would probably be my recommendation for an IDE if some of you guys are still deciding. FOR THOSE OF YOU WHO MISSED THE SECOND CLASS (I think maaybe there were one or two) - there is a separate link for the second class. It's been emailed out and it's in the Discord as well. Make sure to join the second link for the second class. There are two links. Just in case this is still an issue. I'll try to keep tabs on who is still missing the second class next week and reach out to them if the problem persists. ARITHMETIC SYNTAX % - Modulus ** (x/x) - Roots This is some new Python arithmetic syntax that we didn't cover last week. Modulus is a new operation, and it is division, but it returns the remainder instead of the quotient. So 9 mod 3 (or 9 % 3) would equal 0, instead of the regular 3. 16 % 5 == 1, 3 % 1 == 2, and so on. The roots one is pretty simple, maybe you guys have covered this in math class, but raising a number to the power of a fraction is the same as rooting it by the inverse (the inverse is switching the numerator and denominator). So 16 ** (1/2) is 16 root (2/1), which both equal 4. Another example: 27 ** (1/3) == 27 root (3/1) == 3. REVIEW QUESTIONS Answers: 0, -21.5 Solutions: 1 + 14//(3*4) - 2 2 * 3/4 + 1 - 24 = 1 + 14//12 - 2 = 1.5 + 1 - 24 = 1 + 1 - 2 = -21.5 = 0 VARIABLES General information: Variables are very, very important for programming. They make it so you can reference any piece of information as many times as you want without having to type it out again. All you have to do is give the variable's name and the computer will know its value. Because of this, each variable's name has to be unique. Variable names are case-sensitive, so C = 0 and c = 0 are different variables. Think of variables like the bar codes at stores. Each one is unique to its product and when the cashier scans the bar code, the register will know what item it is. Any bar code can be for any product, and any declared variable can hold any data. (This last point is just for Python - in other languages, data type matters.) Declaring variables: In other languages, this part has more steps, but in Python, it's been made really easy. Variables are usually declared at the top of your program, so at the beginning of your code, write out a line with a variable name and a value separated by just one equal sign (e.g. a = 21, b = "hello", c = -10). The spaces are optional but they make it look nicer! Initialization: Initialization is the process of setting a value to a declared variable. In Python, this happens in the same line as declaration (which is giving a variable a name, "declaring" the name to the computer). my_name = "Bonnie" < this is the initialization ^ this is the declaration Naming conventions: An example of a naming convention is demonstrated above with the "my_name" variable. Naming conventions are a set of rules you follow for naming certain parts of your program. They make it easier to know what parts of the program the name refers to just based on the way it is written. We have learned about variables thus far, and the naming convention for these is called snake case. With snake case, every word in the name starts with a lower case, and the spaces are underscores (telephone_nums, time_of_day, num_students (num is short for number)). So when you use snake case to write your variable names, everyone who reads your program will know that those names are for variables. it_is_very_distinctive. There are different naming conventions that you'll learn as there are many things besides variables to name in programming. Data Types: Data types are the types that information can be in programming. These types are mostly universal. When we read information, we don't need a specific distinction as to what type it is - we just read it and understand. But for computers, and especially in different languages (Python is relatively streamlined), it is important to recognize the types of data they receive as only certain things can be done with certain types. You can't do math with words, right? So you have to make sure things like data types are regulated in your code. Integers - all whole numbers, negative or positive. (-1000, 420.) Strings ("") - denoted by the double "" quotations. Anything can be a string if it has these quotes around it. ("hello", "905-192-1119".) I mentioned above that you can't do math with words, but there is a special operation that you can only do with strings called concatenation. This is combining strings together. Just use the addition sign and the computer will return a string that is all of the strings you gave it added together. You could also use single quotes if you felt like it (I do since it's less keys to press and I am lazy haha) but just know that strings are supposed to use double quotes. a = "hello" print("my name" + " is Bonnie.") b = "there" ---------------------------------------- message = a + " " + b + "!" "my name is Bonnie." print(message) ---------------------------- "hello there!" Floats - "Doubles" were also mentioned in class but these don't exist in Python. In other languages, there are size limits to the numbers you can store in specific data types, and the double is just a larger float, but don't worry about it. Floats are all numbers of any size with decimals (2.0, 3.14~, 9000.0000000000001). Characters ('') - denoted by the single '' quotations, this one is just like the double in the way that it is not distinct a data type in Python. Characters are just one letter ('c', 'C', 'z'). But you could write "c" or "C" or "z" and the program would be fine since the character type does not exist. You are just learning this for a fuller understanding of the various data types, and it would be useful if you chose to learn other programming languages. Booleans - Booleans can store two values, True or False. In Python, these values are capitalized, so write them as such when assigning values in your code. In binary, which is the language that the computer ultimately speaks, 0 is False, and 1 is True. (enrolled = True, reading_lesson_notes = True) None - This is exactly what it sounds like. A None-type variable has nothing inside. :( (a = None.) VARIABLE ACTIVITY Create one variable of each data type and print each of them out. Alan's work: Output: --------------------------- 1, 2.0, "Hello", 'c', False USER INPUT input("message") - This is a built-in function that Python has that allows the programmer to accept user input. So anyone who runs this program can type in some information for you to use in your code. Whatever you write in the brackets is what the computer prints to the console before just before accepting user input. The information the input() function receives will always be String type. fav_colour = input("What's your favourite colour? Enter it here: ") print("My favourite colour is " + fav_colour + " too!") -------------------------------------------------------------------- What's your favourite colour? Enter it here: yellow -> My favourite colour is yellow too! -> the program pauses here while it waits for a response. once I type in "yellow" and hit enter, it will unpause and continue on to execute the print statement. Typecasting - As data types are important in programming, and as the information the input() function receives is always a string, now is the time to learn about typecasting. This is how you change the type of data. int(), float(), and str() are the built-in functions we use to do this. Anything in the brackets of those functions is changed into that type. user_num = int(input("Give me a number: ")) print(user_num // 3) -> --------------------------------------------------------- Give me a number: 9 3 -> it is important that we convert to an integer so that we can do math with the user input without raising an error. HOMEWORK Yes, very sad, we have homework this week. Here is the link again: https://docs.google.com/document/d/1grO8moaBkKKICW-MSgEwKuIrxc9OthtZsKZtJ2FZCTc/edit. You only need to do Questions 6-8, so it's not that bad. I'll post full solutions by Saturday night, but ask Alan or me for help throughout the week if you need it. Actually try to do the homework, guys - if it's hard, it means it's good practice, and you can still ask for help anyways, and if it's easy, then you'll be done in no time. Good luck :D HOMEWORK SOLUTIONS ARE UP - 9/25 Thanks for your time this week, everyone. See you soon. -Bonnie (and Alan)
Class 2 - Electric Boogaloo content media
1
0
30
Bonnie Ma
Sep 12, 2021
In Python for ACSL
Hi, guys. My name is Bonnie and I'm the teacher's assistant for this course. Your teacher is Alan (I'm sure you already know these things, haha.) We're glad you're here and we're looking forward to helping you guys prepare for this year's ACSL contests. Homework and lesson notes will be posted to this page soon after class and the solutions will be posted the night before the next class. You can reach Alan and I through email or Discord, whichever you prefer. We'll check both platforms often. Alan: alanxiao211@gmail.com Bonnie: bonnie.ma200@gmail.com, bonnie#7837 (Discord) My contact information is also in my profile in case you need it. Here's our Discord server link (it's a server for all the classes in LoL, you can reach Alan or I through the "python-acsl" channel) - https://discord.gg/s5e9ma34. Nice to meet you all, or for some of you, welcome back :) 10 - 10:40 -> Intro Slides + Intro Survey 10:50-11:30 -> ideone.com, Hello World, PEMDAS in Python Unfortunately, some students today may have missed the second class. In the future, every full class will consist of two sessions, both of which have their own links, just like today. We're sorry for the confusion. If anyone ever misses class in the future, and for those that missed some today, here is everything we did. These kinds of notes will be posted every week. Ask Alan and I for more help whenever you'd like. IDEONE.COM SIGNUP This is an online IDE service that can save your work once you create an account. Follow the below details to create yours (the settings on the left are not important, but make sure the default programming language is "Python 3"). HELLO WORLD The first line of code we've written in this course. If it's written correctly, it should return this in the console below: Print statements print whatever is in the parenthesis to the "output" tab. You can print strings, variables, integers, etc. with this command. Anything you want. In this case, we have printed a string, evidenced by the "" quotes around the text. Other examples of print statements: print(6 * 10) print([1, 2, 3]) print(10 / 2) --------------- ---------------- ---------------- 60 [1, 2, 3] 5.0 --> this decimal makes this value a float **Note: / is the symbol for division. It will return a float value (i.e. 6/3 = 2.0, 10/4 = 2.5). To return an integer, a number with no decimals, use //, the short form for a built-in function called floor. This will return the quotient rounded down to the nearest whole number (i.e. 6/3 = 2, 10/4 = 2). PEMDAS Parenthesis: () Exponents: ** Multiplication: * Division: / -> returns float, // -> returns int Addition: + Subtraction: - You can write equations in Python the same way as real life. You can shove a whole 50-term expression into a print statement and Python will evaluate it with PEMDAS to give you an answer. Try to maintain decimals throughout the entire process to ensure an accurate answer, and then round after all the operations are done if you need to return a formatted answer. ^ This example statement returns 8. (3 x 7 is 21, floored by 4 is 5, plus 3 is 8.) No homework this week, guys. See you all next week. -Bonnie (and Alan)
Class 1 - Welcome to Python for ACSL! content media
3
0
64
Bonnie Ma
Admin
More actions