Python

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

What error occurs when we forget to include quotations around the characters?

A syntax error

Describe a multiline string in Python.

Any string that is enclosed in triple quotes - either double or single as long as they match on both ends. The programmer can literally insert line breaks by using the enter key when they write the code.

What is the output of print("Apple" * 3)?

AppleAppleApple

What is the term for the "=" in this code: firstName = "Ben"

Assignment operator

To display a string that has a single quote in it, the programmer should enclose the string in ____ quotes.

Double (")

What is the output for: print("I need" , "4" , "hamburgers and" , "6" , "hotdogs")

I need 4 hamburgers and 6 hotdogs

What name error occurs when we capitalize the "P" in the print function?

NameError

How can we fix the statement in number 25 so that it will execute correctly? (List two ways)

Rewrite the code as print("Banana" + str(50)) or print("Banana", 50)

What is the correct order of precedence for operations in Python?

Same as in math PEMDAS like below( ) parenthesis** exponents- negation*, /, //, % - multiply and divide left to right+, - add and subtract left to right

To display a string that has a double quote in it, the programmer should enclose the string in ____ quotes.

Single (')

What are the three data types we learned so far?

String (str) Integer Float

T/F Can Python display quotes in strings using print()?

TRUE

What is the purpose of the sep and end parameters in the general print ( ) function?

The sep parameter will set the character between each object that is printed when using the print( ) function with commas. By default the space character is used between each printed object.The end parameter changes the end-line behavior of the print function. By default the newline escape sequence (\n) is used at the end of the line for each print( ) function.

What is the output of print("Banana" + 50)?

This causes a TypeError because in Python it is illegal to try to add a string and a non-string (in this case an int) together with the +

What is the purpose of the input() function?

To ask the user to interact with the program. varName = input(StringPrompt)

What is the purpose of the print() function?

To display output on the screen

What character is used in Python to designate a comment?

To display the type of data. The general syntax is type(dataValue)

What is the purpose of the type() function?

To display the type of data. The general syntax is typed(dataValue). In the order to display it on the screen you must print it.

T/F The programmer can change variable values from one data type to another.

True in Python variables can have any type of values at any type of value at any time during the life of the program.

T/F Single quotations can be used to identify a string.

True remember that quotations MUST be used to identify a literal string.

Give an example of a NameError

When you misspell or mistype a variable or keyword in python. (Type("help")) would cause a NameError because the T is a capital letter when it should be lower case.

Write the code for the type() function to display the type() for: 2468 and "cartoons are funny" (two lines)

to display it on the screen useprint(type(2468)) and print(type("cartoons"))

List and describe the purpose of each mathematical operator.

+ addition- subtraction when between two values- negation when in front of one value only* multiplication/ division will ALWAYS result in a float// integer division will return the whole number part of a division problem as an integer% modulus (remainder division) will return the remainder part of a division problem as an integer** exponentiation written like base ** power

What python function always returns a string value?

input( )

Correct the code: print(type"1024")

print(type("1024"))

What is a Variable?

to store a value for later use in a program.


Ensembles d'études connexes

Programming: Chapters 1, 2, and 3

View Set

Human growth and development Nemcc

View Set

Chapter 7: Electrolyte Imbalances Multiple choice

View Set