Getting Started Using Python

Ace your homework & exams now with Quizwiz!

you're talking about different things. terry's choice had what are called runtime errors. the program couldnt run because

one line referenced a variable, named birth_month, that had never been defined before it was used. the program tried to execute but when it got to the line that needed to output the value of birth_month it had to stop -- there was no value for the variable birth_month

okay. let's say i enter "one_name = Jamie" on one line. If i wanted the result to be "Your name is Jamie" what should I enter on the next line.

print ("Your name is", one_name)

Drag the variable name to the error it contains. You can (and probably should) put more than one selection into a category

spaces in the name - my 1st pet - first car2020 first character incorrect - 1st_pet - 90_equals_A special characters - pet's_name - #1_pet'sName acceptable - first_pet - love_my_red_bicycle

the modulus operator is indicated, in Python, by the percent sign (%). it is the remainder after dividing one integer by another. for example,

- 17 % 5 = 2 - 21 % 7 = 0

one more thing. when you declare a variable and give it an initial value, in Python, the variable will automatically be assigned the datatype of that value. For example, if I entered my_grade = 85, the computer will assume my_grade is an integer datatype because 85 is an integer. which of these are correct datatype identifications?

- my_name = 45.00 is a float datatype - my_name = "23" is a string datatype - my_name = 23 is an integer datatype

Pick which of following correctly identifies a variable and a datatype

- my_variable = float(23.7) - my_variable = int(15) - my_variable = str("Hi!")

There are many IDEs that you can use to write Python code but we recommend..

IDLE because it comes with Python when you download Python. It's free and easy to use.

The shell is great for testing out a few lines of code but if you want to write a whole computer program, you do that in the Editor. Then

after you save your program as a file, with the .py extension, you can run it. it will run in the shell

That's a great question. Before you can create a program in any language that can actually be executed, you need to write code in a form the computer can understand. That means more than just the characters you type, but you need a special type of software called..

an IDE. it's a software application that includes a source code editor

IDLE is not only free, but it comes automatically with your download of Python. All you need to do is

go to www.python.org/downloads and pick your operating system. be sure to select the latest version of Python 3.

I know its confusing. let's start by talking about what a variable actually is. a variable..

is the name you, the programmer, give to identify a storage location in the computer's memory

IDLE opens in what is called

the interactive shell. here you can enter python code after the >>> prompt. then press enter and if your code is valid, you'll see the result

good question, jamie! program C has what is known as a logic error. that's when the results are okay, as far as the computer is concerned, but not what you want.

the output of program C was one line of text that never displayed the user's name, their age at their next birthday or their birth month

sure. let's start with this: If I enter "x=2.5" on one line in the shell and "y=30.8" on the next line, what should i enter on the third line to see the result of multiplying 30.8 by 2.5?

y * x

The problem with this code is

you used break as a variable name. the word break is a Python keyword. it has a special reserved meaning in the Python language and cannot be used as a variable name

okay. here are three short programs. only one will run correctly. i'll tell you which is the one without errors and can help you identify the errors in the other two

Sample program B

The programs I wrote are on the right. Two have errors but one will run correctly and give the correct result. If you try these yourself, the correct answer is 37.0. Can you pick the correct program?

Sample program C

there's one more really important thing. each variable has a datatype. datatypes are important because

computers store different types of data in different ways

order of operations

first - parentheses second - exponentiation third - multiplication - division - modulus last - addition - subtraction


Related study sets

Personal Financial Management final

View Set

SIE ( Understanding Products and Their Risks ) and (Understanding Trading, Customer Accounts, and Prohibited Activities)

View Set

DMI 65 Quiz 1 - Chapters 1 (1-60) 10 (61-79)

View Set