MSYS 21

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

String operators

Arithmetic operators cannot be used on strings, with some "exceptions".

> : less than >= : less than or equal < : greater than <= : greater than or equal == : equal != : not equal

Name the 6 comparison operators.

Value

One of the most basic things that you will use in a Python program

math module

We can extend Python to give us nifty mathematical operators by importing what module?

Integer, float, and string

Type of values in Python

math.log10(x)

Used to get the base-10 logarithm of a number.

math.gcd(x, y)

Used to get the greatest common denominator of two numbers.

math.sin(number)

Used to get the sine of a number.

math.pi

Used to obtain the value of pi.

math.perm(value, value) Ex. math.perm(6, 3) 120

Used to perform permutations.

math.floor( ) Ex: math.floor(6.14) 6

Used to round down a value.

Can produce different outputs for different purposes; Contains features that make debugging and writing programs easier.

Advantages of Jupyter

Processes performed by an IDE.

Allows you to create, edit, and run programs written in a given language.

Expressions and Operators

Combinations of values, variables, and operators that represent a value.

int(value)

Converts a string or number into an integer.

str(value)

Converts a value into a string.

A float contains decimals while integer is a whole number without decimals. A string on the other hand, is a value within quotations marks (single or double quotes).

Difference of an integer and a float and a string

7.0 2.0 "Hello, world!"

Examples of value in Python

Gives instructions to tell the computer to do something. Ex: Assignment: x = y + z Printing: print(x)

Expressions yield values, but statements do what?

input( ) Ex: n = input() # Program waits for input [IN]: Joker print("Looking cool, " + n) [OUT]: Looking cool, Joker

Function used so that the program waits for the user to type in something. The program resumes once the user has entered something.

1) Think of what it will be used for and what it represents 2) The variable name can contain letters, digits, and underscores 3) It cannot begin with a digit, or be existing keywords like class, if, not, except, etc.

How to name variables?

Variable

Name that corresponds to a value. Allows access to a value after its creation.

1) and 2) or 3) else

Name the 3 comparison operators.

+ (plus sign) - (minus sign) / (division sign) * (multiplication sign) ** (raise to the power of sign) % (modulo: division sign to obtain remainders)

Name the 6 common arithmetic operators and their functions.

print(value)

Prints the value onto the console.

abs(number)

Returns the absolute value of a number.

max(x, y, z...)

Returns the largest of all the values provided.

min(x, y, z...)

Returns the smallest of all the values provided.

round(number)

Rounds a number to the nearest interval.

Visual Studio Code (VSCode)

Some IDEs support more than one language, give one example:

+ Ex: first = "Hi" second = " " third = "there." first + second + third Hi there.

String operator used to add or "concatenate" strings together.

*

String operator used to repeat strings.

# hashtag for single-line comments; ' ' ' three single-quotes or double quotes in between the multi-lined comments ' ' '

Symbols used for Comments in a Python code.

True

T or F. Expressions can translate into a boolean.

False (Jupyter will "evaluate" the very [last line] of your code and output its value)

T or F. Jupyter will "evaluate" the last line to the first line of your code and output its value.

False (Typing an integer with a leading zero will raise an error) Ex: 012345 outputs --> SyntaxError: invalid syntax

T or F. Typing leading zeros outputs the same integer without leading zeros.

False (Python interprets these as a group of distinct integers) Ex: 100000 not 100,000

T or F. When writing large numbers in Python, we use commas.

Notebook and Lab

Two flavors of Jupyter

Boolean

Type of value which can be True or False.

Jupyter

Web-based IDE that can run Python programs

Integrated Development Environment

What does IDE stand for?

negates a boolean value

What does the "not" boolean value do?

type( )

What function is used to verify the type of a given value?

and

What is the comparison operator that outputs True if both are True, else False.

or

What is the comparison operator that outputs True if one is True, else False.

Strings We need to convert them to integers using the int() function. Ex: baseArea = int(input('Base Area: ')) [IN]: Base Area: 200 height = int(input('Height: ')) [IN]: Height: 150 volume = baseArea * height # No error print(volume) [OUT]: 30000

What is the initial type of the value obtained from the input( ) function?

They are all valid!

Which of the following statements are invalid?: s = 12345 hello = "Hello, world! y = 3.14 y = s s = hello


Ensembles d'études connexes

Egan's Chapter 39: humidity and bland aerosol therapy

View Set

Ch. 1: Understanding Medical Word Elements: Learning Activity 1-1

View Set

Section 5: Generational Differences

View Set