Partial preview of the text
Download Intro to Programming - Python Review with complete verified solutions 2025.pdf and more Exams Biology in PDF only on Docsity!
Intro to Programming - Python Review with complete verified solutions 2025 The______ statement is a command : built in to Python. When you run the print() -py file, the Python interpreter knows t to display whatever is contained between the (). b=6 Print the value of a variable "b" that print(b) ; equals 6. integer A variable type that holds whole 9 : numbers A variable type containing a decimal float or oa + point The value of this variable type ; : doesn't necessary need to be a letter. string : We can also have____s that are numbers. print(c) Use this statement to check the value i of a variable "c" boolean A Python variable which can only have two values, True or False. These True of False values reduce down to a 1 or 0, on or off. myBool = True print(myBool) Create a boolean variable that is set to true (case sensitive) list "A variable type which can store multiple items together as one variable, and each of those items can actually have different types. For example, the first item could be integer, second item a float, and third item a string. myList = [4, 6.5, ‘a'] print(myList) myList has three items in and to access each individual item, we use the index of the item. Indexing starts at 0, so the first item is myList[0], the second is myList[1], and the third is myList[2] print(myList[0]) + print(myList[1]) print(myList[2]) exponentation z=a**2 print(z) addition, multiplication, division | z2=at+(b*z)/a t print(z2) radius = 10 area = 3.14 radius*2 circ = 2 3.14 radius print("the area is:",area) print("the circumference is:",circ) ! Given a circle with a radius of 10 ! units. Calculate the area and i circumference ("circ") of the circle. The formula for area is a = pi*r42 ! The formula for circumference is 2pir seconds = 200 mins = int(seconds / 60) s = seconds % 60 print("200 seconds is ",mins, " mins and ",s, "seconds") : Print 200 seconds as a mixed i expression of minutes and seconds. modulus (%) To convert decimals to mixed : expressions, use the ___ { convert 200 seconds into minutes and seconds, use the___ of dividing by 60.) (i.e, to if mpg < 15: print("uber polluter") elif mpg > 30: print(“nice job") else: print("not bad") #if mpg < 15, print uber polluter i #if mpg > 30, print nice job i #if mpg between 15 and 30, print not i bad < less than > | greater than <= | less than or equal to >= | greater than or equal to == | equal to I= | not equal | Relational operators all perform the : same task of specifying a relation in ifa == 3: an if statement, that is then evaluated print("a equals 3") to be true or false For example, to check if a is equal to 3, you use... ais greater than or equal to 4 Output for the following: a=5 ifa<4: print("a is less than 4") else: print("a is greater than or equal to 4") If the "if" is true The only time the "else" block won't execute If the guess was too high or too low, tell them, and prompt them to guess again. If the guess was correct, tell them, "that's it. the number was __."_! : while numFound == False: guess = int(input("Guess a number : between 0 and 100: ")) { numFound = False | if guess > number: print("You guessed too high") guess = int(input("Guess again: ")) elif guess < number: print("You guessed too low") guess = int(input("Guess again: ")) else: print("That's it. The number was ", { number) { numFound = True iterator A type of loop in Python that uses the { keyword "for." range A type of collection that is a sequence ! of numbers, such as 1,2,3,4,5. numbers = range(1,6) Generate the sequence of numbers 1 1,2,3,4,5. for x in range(1,6): print(x * 2) Multiply each number ("x") within the given range (of 1 to 5) by 2. myList = ['a’, 2, ‘puppies’, 4] for item in myList: print(item) One of the other collection types we ! saw was a list. In a list, it's a collection of items that can be of different types and we can iterate over the list in the same way that we iterate over a string or a sequence of numbers For example...