98-381:MTA: Introduction to Programming using Python

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

<

Less than

math.floor

Lowers a floating number to its base whole number.

>

Greater than

>=

Greater than or equal

What is the proper syntax for a Pydoc in Python?

-m Represents the name of a Python module.

What happens when a block of code runs through an if/elif/else statement?

If the first condition is true the code wont continue to the other statements. If its false it would go through the other statements.

What keyword is used to check to see if the word "nine is part of the quote. quote = " A stitch in time saves nine" print("nine" [ ] quote )

In

continue

In Python it skips back to the beginning of a loop.

print some_list[0:23]

In a large list Prints items starting with 0 - 22

Which type of error is an error in which programming code causes a divide by zero error? User Syntax Runtime Logic

A divide by zero error occurs when an app runs. It is not cause by bad syntax or bad logic as bad logic will still run but return an unanticipated value. So it is a Runtime Error

for i in range(starting number, ending number, increment):

A for loop structure

os

Allows Python code to create folders.

sys

Can display error messages, exception information and other system information that might not show.

Pydoc

Is a term for Python that generates documentation on Python Modules. But it is not a self-contained executable that can be run from a command-line prompt.

os.path

Operating system path module: allows many functions to occur on a specified path. Ex: os.path exists will return a true or false if a file does or doesn't exist. Can find specific files and folders.

\n

Print new line

print some_list[3:15]

Prints list items 3 - 14 If you are making an alphabet list In this case letters d - o

print some_list[1::2]

Prints out every other item starting with index 1

print some_list[-2:]

Prints out the last two items in a list.

print some_list[:2]

Prints the first two items. The zero is optional, but is mostly used as a placeholder.

^

Raises what ever power the number is.

math.round

Rounds a number

io

Used to read from and write files.

\\

Uses the backslash character. ' \ '

/ (forward slash)

Will divide and return the sum.

Pydoc Example Code: Python -m pydoc pass

Will show documentation on the pass module within Python. Pydoc, which generates documentation on Python modules, is part of the Python command prompt. The -m after the Python command prompt with the Pydoc command and the name of the module will produce documentation on the module.

Look at the example: What keyword is missing to prevent an infinite loop. while True: [ ]

break

You are writing a code to check to see if a file exists. If it does, it should open in append mode. If it does not, it should open in write mode.

import os if os.path.isfile('results.txt'): writeFile = open('results.txt','a') else: writeFile = open('results.txt','w')

<=

less than or equal to

break

A Python keyword / function used in a code for when a loop needs to exit or quit. Ex: captialGuess = input("What is the capital of California?") numberOfGuesses = 1 while capitalGuess != "Sacramento": numberOfGueses = numberOfGuesses+1 if numberOfGuesses >3: print("You guessed incorrectly three times. Game over.") break capitalGuess = input("Guess again.")

The correct syntax of an If statement is?

A colon terminates the condition at the end of an if statement. Anything in the statement needs to be indented. height = 5 width = 5 if height == width: print("You have a square")

pass

A placeholder where no code should run in a conditional statement. Ex: def calcArea(height,width): if height > 0 and width > 0: print(height * width) else: pass

\

An escape key that allows you to continue on the next line.

print some_list[::10]

In a large list it will print the first item and skip every nine elements then print the tenth item.

f

Indicates the presence of formatted text, like a variable inside a sentence. Ex: width = int(input("Enter a width: ")) height = int(input("Enter a height: ")) area = width * height print(f"The area of your shape is {area}") The f is used to tell python that the print statement needs to print the area variable inside the text(string).

math.ceil

Takes a floating point number and rounds it to the next whole number.

mod

The modulus operator, sometimes used in calculations.

==

equal to

Exam Practice

https://exam-files.com/microsoft/98-381/ and https://www.py4e.com/

\t

inserts a tab

!=

not equal to

You have to pieces of text that need to be concatenated. One adds two strings together and the other requires a variable value to be displayed within a sentence.

price = 5.9 sqft = 100 print("The current price per square foot is " , price) print(f "You need enough for{sqft} sqft.") The comma is used to concatenate a string and variable in a print statement.

In a command-line area, which command would run a Python file called calcArea? python calcArea python -calcArea.py python calcArea.py pydoc calcArea.py

python calcArea.py When running a file in a command line scenario, the word python is used followed by the name of the file(if the prompt is in the same folder as the file).

%

returns the remainder or modulus

How would you round the number held in the variable pi to 3.14 pi = 3.14159265

round(pi,2) The number that needs to be rounded is the first parameter while the second number is the number of decimal places which is the second parameter.


Ensembles d'études connexes

Pelvis & Hip Pathology & Questions

View Set

Chapter 6: Culture, Media, and Communication

View Set