Intro to computer science python dierbach download pdf






















Read also:. Data Science Projects with Python - A case study approach to gaining valuable insights from real Data Science Projects with Python A case study approach to gaining valuable insights from real data, 2nd Edition. Information Users of Guests are not allowed to comment this publication.

Through real-world examples, you'll learn how to work with numbers, text, big data sets, and files. Then you'll see how to create and use your own data types. The incremental examples show you the steps and missteps that happen while developing programs, so you know what to expect when you tackle a problem on your own. Inspired by "How to Design Programs" HtDP , you'll learn a six-step recipe for designing functions, which helps you as you start to learn the concepts--and becomes an integral part of writing programs by the end.

As you learn to use the fundamental programming tools in the first half of the book, you'll see how to document and organize your code so that you and other programmers can more easily read and understand it.

Beyond the basics, you'll learn how to ensure that your programs are reliable, and how to work with databases, download data from the web automatically, and build user interfaces. Most importantly, you'll learn how to think like a professional programmer. You'll need to download Python 3, available from "python. Author : John S. Tbook gives beginning students an introduction to. Author : Dierbach Publisher: ISBN: Category: Page: View: Read Now » Bioinformatics - the use of computers to retrieve, process, analyze and simulate biological information - promises to revolutionize the process of drug discovery and development.

In addition, the state-of-the-art in bioinformatics is evaluated equally from a global view by introducing real application scenarios such as genome projects that require the use of a whole set of bioinformatics tools. The profound knowledge on bioinformatics presented here not only enables readers to go beyond a mere push-button approach to using bioinformatics software and interpreting the data generated appropriately.

It is also essential to assess the potential and limitations of today's bioinformatics software and future challenges. Directed to all those involved in the use or development of new bioinformatics tools - scientists and managers from the fields of molecular biotechnology, pharmaceutics, and medicinal chemistry - this book will lead one step further on the way to rational drug design. Author : John V. It provides students with skills that will enable them to make productive use of computational techniques, including some of the tools and techniques of data science for using computation to model and interpret data.

This new edition has been updated for Python 3, reorganized to make it easier to use for courses that cover only a subset of the material, and offers additional material including five new chapters.

Students are introduced to Python and the basics of programming in the context of such computational concepts and techniques as exhaustive enumeration, bisection search, and efficient approximation algorithms.

Although it covers such traditional topics as computational complexity and simple algorithms, the book focuses on a wide range of topics not found in most introductory texts, including information visualization, simulations to model randomness, computational techniques to understand data, and statistical techniques that inform and misinform as well as two related but relatively advanced topics: optimization problems and dynamic programming.

The Python programming topics include the reserved keywords,identifiers, variables, operators, data types and their operations, flowcontrol techniques which include decision making and looping, modules, filesand exception handling techniques. Advanced topics like Python regularexpressions, Database Programming and Object Oriented Programming concepts arealso covered in detail.

All chapters have worked out programs, illustrations,review and frequently asked interview questions. The simple style of presentationmakes this a friend for self-learners.

More than solved lab exercisesavailable in this book is tested in Python 3. The book covers syllabus for more than 35 International Universities and45 Indian universities like Dr. Author : Mark J. Social Computing and Programming with Python Introduction to Computing and Programming in Python is a uniquely researched and up-to-date volume that is widely recognized for its successful introduction to the subject of Media Computation.

Emphasizing creativity, classroom interaction, and in-class programming examples, Introduction to Computing and Programming in Python takes a bold and unique approach to computation that engages students and applies the subject matter to the relevancy of digital media.

Python has a simple syntax. Python pro- grams are clear and easy to read. At the same time, Python provides powerful programming features, and is widely used.

Python is well supported and freely available at www. Jason E. An IDE is a bundled set of software tools for program development. A debugger provides a means of taking control of the execution of a program to aid in finding program errors.

Python is most commonly translated by use of an interpreter. Thus, Python provides the very useful ability to execute in interactive mode. The window that provides this interaction is referered to as the Python shell. Interacting with the shell is much like using a calculator, except that, instead of being limited to the operations built into a calculator addition, subtraction, etc.

Example use of the Python shell is demon- strated in Figure Here, the expression 2 1 3 is entered at the shell prompt Although working in the Python shell is convenient, the entered code is not saved. Thus, for program development, a means of entering, editing, and saving Python programs is provided by the program editor in IDLE.

Details are given below. We discuss the creation of Python mod- ules in Chapter 7. For example, the math module provides additional mathematical functions. The random module provides the ability to generate random numbers, useful in programming, as we shall see.

In order to utilize the capabilities of a given module in a specific program, an import statement is used as shown in Figure The example in the figure shows the use of the import math statement to gain access to a particular function in the math module, the factorial function. The syntax for using the factorial. We will make use of library mod- ules in Chapter 2. In section 1.

The Python Standard Library is a collection of modules, each providing specific functionality beyond what is included in the core part of Python. Since all computer programs input data, process the data, and output results, we look at the notion of a variable, how to perform some simple arithmetic calculations, and how to do simple input and output.

Variables One of the most fundamental concepts in programming is that of a variable. Variables are discussed in detail in Chapter 2. Thus, whenever variable n appears in a calculation, it is the current value that n is assigned to that is used, as in the following,. If variable n is assigned a new value, then the same expression will produce a different result,. Addition, subtraction, and division use the same symbols as standard mathematical notation,. Multiplication is never denoted by the use of parentheses as in mathematics, as depicted below,.

Note that parentheses may be used to denote subexpressions. Finally, we see how to input informa- tion from the user, and display program results. Basic Input and Output The programs that we will write request and get information from the user. In Python, the input function is used for this purpose,. Characters within quotes are called strings. This particular use of a string, for requesting input from the user, is called a prompt.

The input function displays the string on the screen to prompt the user for input,. The print function is used to display information on the screen in Python. Note that a comma is used to separate the individual items being printed, causing a space to appear between each when displayed.

Thus, the output of the print function in this case is Hello Charles, and not HelloCharles. This will be covered in the chapters ahead. In Python, input is used to request and get information from the user, and print is used to display information on the screen.

Commons Wikimedia name and responds with a greeting. When finished, save the program file by selecting Save As under the File menu, and save in the appropriate folder with the name MyFirstProgram.

To run the program, select Run Module from the Run menu or simply hit function key F5. If you have entered the program code correctly, the program should execute as shown in Figure If, however, you have mistyped part of the program resulting in a syntax error such as mistyping print , you will get an error message similar to that in Figure In that case, go back to the program window and make the needed corrections, then re-save and re-execute the program. You may need to go through this process a number of times until all the syntax errors have been corrected.

Frank Drake conducted the first search for radio signals from extraterrestrial civilizations in. In order to estimate the number of civili- zations that may exist in our galaxy that we may be able to communicate with, he developed what is now called the Drake equation.

The Drake equation accounts for a number of different factors. The Drake equation is simply the multiplication of all these factors, giving N, the estimated number of detectable civilizations there are at any given time,. Figure shows those parameters in the Drake equation that have some consensus as to their correct value. Given the uncertainty of the remaining factors, you are to develop a program that allows a user to enter their own estimated values for the remaining six factors p, n, f, i, c, and L and displays the calculated result.

We only need to understand the equation provided. The data to be represented consist of numerical values, with the Drake equation as the algorithm. The overall steps of the program are depicted in Figure The only programming elements needed are input, assignment, and print, along with the use of arithmetic operators. An implementation is given in Figure Example execution of the program is given in Figure First, note the program lines beginning with the hash sign,.

In Python, this symbol is used to denote a comment statement. A comment statement contains information for persons reading the program. Comment statements are ignored during program execution—they have no effect on the program results. In this program, the initial series of comment statements lines 1—23 explain the Drake equation and provide a brief summary of the purpose of the program.

Comment statements are also used in the program to denote the beginning of each program section lines 25, 32, 40, and These section headers provide a broad outline of the program following the program design depicted in Figure The program welcome section lines 25—30 contains a series of print instructions displaying output to the screen.

Each begins with the word print followed by a matching pair of parentheses. Within the parentheses are the items to be displayed. In this case, each contains a particular string of characters. It simply causes the screen cursor to move down to the next line, therefore creating a skipped line in the screen output. Later we will see another way of creating the same result. The following section lines 32—38 contains the instructions for requesting the input from the user.

Previously, we saw the input function used for inputting a name entered by the user. In that case, the instruction was of the form,. The input function always returns what the user enters as a string of characters. However, in this program, numbers are being entered, not names.

Thus, in, the following,. The addition of the int. This will be discussed more fully when numeric and string character data are discussed in Chapter 2. Note that since some of the input values were meant to be percentages p, f, i, and c , those values in the equation are each divided by Finally, lines 44—47 display the results.

A test case is a set of input values and expected output of a given pro- gram. A test plan consists of a number of test cases to verify that a program meets all requirements.

Such a test plan is given in Figure Based on these results, we can be fairly confident that the program will give the correct results for all input values. Search online for two areas of computer science other than those given in the chapter.

For the Man, Cabbage, Goat, Wolf problem: a List all the invalid states for this problem, that is, in which the goat is left alone with the cabbage, or the wolf is left alone with the goat.

Rather than a sequence representation, a set repre- sentation can be used. In this representation, if an item is on the east side of the river, its symbol is in the set, and if on the west side, the symbol is not in the set as shown below,. Give the sequence of states for your solution to the problem using this new state representation. For a simple game that starts with five stones, in which each player can pick up either one or two stones, the person picking up the last stone being the loser, a Give a state representation appropriate for this problem.

Section 1. Using the algorithm in Figure , show all steps for determining the day of the week for January 24, Note that is not a leap year. Using the algorithm in Figure , determine the day of the week that you were born on. Suppose that an algorithm was needed for determining the day of the week for dates that only occur within the years — Simplify the day of the week algorithm in Figure as much as possible by making the appropriate changes. As precisely as possible, give a series of steps an algorithm for doing long addition.

What is the number of bits in 8 bytes, assuming the usual number of bits in a byte? Convert the following values in binary representation to base Show all steps. Convert the following values into binary base 2 representation. What is in common within each of the following groups of binary numbers?

Give two specific examples of an application program besides those mentioned in the chapter. For each of the following statements in English, indicate whether the statement contains a syntax error, a logic semantic error, or is a valid statement. For each of the following arithmetic expressions for adding up the integers 1 to 5, indicate whether the expression contains a syntax error, a semantic error, or is a valid expression.

Give one benefit of the use of a compiler, and one benefit of the use of an interpreter. Use the Python Interactive Shell to calculate the number of routes that can be taken for the Traveling Salesman problem for: a 6 cities b 12 cities c 18 cities d 36 cities Enter the following statement into the interactive shell:. Is this a syntax error or a logic error?

For the Traveling Salesman problem, a Update the list representation of the distances between cities in the table in Figure to add the city of Seattle. The distances between Seattle and each of the other cities is given below. Which of the following capabilities does an integrated development environment IDE provide? The Python shell is a window in which Python instructions are immediately executed.

Suppose that the math module of the Python Standard Library were imported. What would be the proper syntax for calling a function in the math module named sqrt to calculate the square root of four? What is the value of variable n after the following instructions are executed?

Which of the following is a proper arithmetic expression in Python? Exactly what is output by the following if the user enters 24 in response to the input prompt.

Write a simple Python program that displays the following powers of 2, one per line: 21, 22, 23, 24, 25, 26, 27, Write a Python program that allows the user to enter any integer value, and displays the value of 2 raised to that power. Your program should function as shown below. What power of two? Write a Python program that allows the user to enter any integer base and integer exponent, and displays the value of the base raised to that exponent.

What base? Write a Python program that allows the user to enter a four-digit binary number and displays its value in base Each binary digit should be entered one per line, starting with the leftmost digit, as shown below. Enter leftmost digit: 1 Enter the next digit: 0 Enter the next digit: 0 Enter the next digit: 1 The value is 9.

Write a simple Python program that prompts the user for a certain number of cities for the Traveling Salesman problem, and displays the total number of possible routes that can be taken. How many cities? The program should then display,. Hello firstname lastname Welcome to Python! The value of R should remain as 7. Design the program so that the only values that the user is prompted for are how many planets per star can support life, n, and the estimated number of years civilizations last, L.

Develop a set of test cases for your pro- gram with the included test results. Develop and test a program that allows the user to enter an integer value indicating the number of cities to solve for the Traveling Salesman problem. The program should then output the number of years it would take to solve using a brute force-approach. Make use of the factorial function of the math module as shown in Figure Estimate the total amount of time it takes by using the assumptions given in section 1.

Based on the information provided about the game of chess in section 1. Assume the current world population to be 7 billion. With this chapter, we begin a detailed discussion of the concepts and techniques of computer programming. The sheer amount of data being created is staggering. Chain stores gener- ate terabytes see Figure of customer informa- tion, looking for shopping patterns of individuals.

Facebook users have created 40 billion photos re-. A certain radio telescope is expected to generate an exabyte of information every four hours.

All told, the current amount of data created each year is estimated to be almost two zettabytes, more than doubling every two years. In this chapter, we look at how data is represented and operated on in Python. A literal is a sequence of one of more characters that stands for itself, such as the literal We look at numeric literals in Python next. A literal is a sequence of one or more characters that stands for itself. The letter e is also used in exponential notation, shown in the next subsection.

Commas are never used in numeric literals. Figure gives additional examples of numeric literals in Python. Since numeric literals without a provided sign character denote positive values, an explicit positive sign character is rarely used.

Next we look at how numeric values are represented in a computer system. A numeric literal is a literal containing only the digits 0—9, a sign character 1 or 2 and a possible decimal point.

Limits of Range in Floating-Point Representation There is no limit to the size of an integer that can be represented in Python. Floating-point values, however, have both a limited range and a limited precision. Python uses a double-precision standard format IEEE providing a range of to with 16 to 17 digits of precision. To denote such a range of values, floating-points can be represented in scientific notation,. It is important to understand the limitations of floating-point representation.

For example, the mul- tiplication of two values may result in arithmetic overflow, a condition that occurs when a calcu- lated result is too large in magnitude size to be represented,. Similarly, the division of two numbers may result in arithmetic underflow, a condition that occurs when a calculated result is too small in magnitude to be represented,. This results in 0.

We next look at possible effects resulting from the limited precision in floating-point representation. Arithmetic overflow occurs when a calculated result is too large in magnitude to be represented. Arithmetic underflow occurs when a calculated result is too small in magnitude to be represented.

Limits of Precision in Floating-Point Representation Arithmetic overflow and arithmetic underflow are relatively easily detected. The loss of precision that can result in a calculated result, however, is a much more subtle issue. Since any floating-point representation necessarily contains only a finite number. Here, the repeating decimal ends after the 16th digit. Consider, therefore, the following,. The answer is that Python displays a rounded result to keep the number of digits displayed manageable.

However, if we use multiplication instead, we again get the rounded value displayed,. The bottom line, therefore, is that no matter how Python chooses to display calculated results, the value stored is limited in both the range of numbers that can be represented and the degree of preci- sion. For most everyday applications, this slight loss in accuracy is of no practical concern.

How- ever, in scientific computing and other applications in which precise calculations are required, this is something that the programmer must be keenly aware of. Since any floating-point representation contains only a finite number of digits, what is stored for many floating-point values is only an approximation of the true value. Built-in format Function Because floating-point values may contain an arbitrary number of decimal places, the built-in format function can be used to produce a numeric string version of the value containing a specific number of decimal places,.

In these examples, format specifier '. For very large or very small values 'e' can be used as a format specifier,. In this case, the value is formatted in scientific notation, with six decimal places of precision. For- matted numeric string values are useful when displaying results in which only a certain number of decimal places need to be displayed,.

The built-in format function can be used to produce a numeric string of a given floating-point value rounded to a specific number of decimal places. In Python, string literals may be delimited surrounded by a matching pair of either single ' or double " quotes. Strings must be contained all on one line except when delimited by triple quotes, discussed in Chapter 7.

We have already seen the use of strings in Chapter 1 for displaying screen output,. As shown in the figure, a string may contain zero or more characters, including letters, digits, special characters, and blanks. A string consisting of only a pair of matching quotes with nothing in between is called the empty string, which is different from a string containing only blank characters.

Both blank strings and the empty string have their uses, as we will see. Strings may also contain quote characters as long as different quotes are used to delimit the string,. If this string were delimited with single quotes, the apostrophe single quote would be considered the matching closing quote of the opening quote, leaving the last final quote unmatched,.

Thus, Python allows the use of more than one type of quote for such situations. The convention used in the text will be to use single quotes for delimiting strings, and only use double quotes when needed.

A string literal, or string, is a sequence of characters denoted by a pair of matching single or double and sometimes triple quotes in Python. The Representation of Character Values There needs to be a way to encode represent characters within a computer. Although various en- coding schemes have been developed, the Unicode encoding scheme is intended to be a universal encoding scheme.

Unicode is actually a collection of different encoding schemes utilizing between 8 and 32 bits for each character. Currently, there are over , Unicode-defined characters for many of the languages around the world. Unicode is capable of defining more than 4 billion characters. UTF-8 encodes characters that have an ordering with sequential numerical values. For example, 'A' is encoded as 65 , 'B' is encoded as 66 , and so on. This is true for character digits as well, '0' is encoded as 48 and '1' is encoded as This under- scores the difference between a numeric representation that can be used in arithmetic calculations vs.

Python has means for converting between a character and its encoding. For example, ord 'A' is The chr function gives the character for a given encoding value, thus chr 65 is 'A'. Functions are discussed in Chapter 5. While in general there is no need to know the specific encoding of a given character, there are times when such knowledge can be useful.

Unicode is capable of representing over 4 billion different characters, enough to represent the characters of all languages, past and present. Rather, they control the display of output among other things. Control characters do not have a corresponding key- board character. Therefore, they are represented by a combination of characters called an escape sequence. An example of its use is given below,. Hello Jennifer Smith. Control characters are nonprinting characters used to control the display of output among other things.

An escape sequence is a string of one or more characters used to denote control characters. We now look at how the format function can be used to control how strings are displayed.

As given above, the format function has the form,. For example, to produce the string 'Hello' left-justified in a field width of 20 characters would be done as follows,. Formatted strings are left-justified by default.

Another use of the format function is to create strings of blank characters, which is sometimes useful,. Finally blanks, by default, are the fill character for formatted strings. However, a specific fill char- acter can be specified as shown below,. Have a Nice Day! There are two ways in Python to do deal with such situations—implicit and explicit line joining. We discuss this next.

Implicit Line Joining There are certain delimiting characters that allow a logical program line to span more than one physical line. This includes matching parentheses, square brackets, curly braces, and triple quotes.

For example, the following two program lines are treated as one logical line,. Matching quotes except for triple quotes, covered later must be on the same physical line. For example, the following will generate an error,.

Matching parentheses, square brackets, and curly braces can be used to span a logical program line on more than one physical line. Program lines that end with a backslash that are not part of a literal string that is, within quotes continue on the following line,. In Python, the complete Hello World program is comprised of one program line,.

The statements on lines 1, 3, and 6 are comment statements, introduced in Chapter 1. They are ignored during program execution, used to provide information to those reading the program. Double quotes are used to delimit the corresponding string, since the single quotes within it are to be taken literally.

Note from the program execution that there is a Unicode encoding for the blank character 32 , as well as the exclamation mark Indicate which of the following are valid numeric literals in Python. Which of the following would result in either overflow or underflow for the floating-point representation scheme mentioned in the chapter. Exactly what is output by print format Which of the following are valid string literals in Python. Which of the following results of the ord and chr functions are correct?

However, the true usefulness of a computer program is the ability to operate on different values each time the program is executed. This is pro- vided by the notion of a variable. We look at variables and identifiers next. A variable is a name identifier that is associated with a value, as for variable num depicted in Figure Variables are assigned values by use of the assignment operator, 5, num 5 10 num 5 num 1 1. Assignment statements often look wrong to novice programmers.

Mathematically, num 5 num 1 1 does not make sense. In computing, however, it is used to increment the value of a given variable by one. It is more appropriate, therefore, to think of the 5 symbol as an arrow symbol, as shown in Figure When thought of this way, it makes clear that the right side of an assignment is evaluated first, then the result is assigned to the variable on the left.

An arrow symbol is not used simply because there is no such character on a standard computer keyboard. Variables may also be assigned to the value of another variable or expression, discussed below as depicted in Figure Variables num and k are both associated with the same literal value 10 in memory. One way to see this is by use of built-in function id,.

The id function produces a unique number identifying a specific value object in memory. Since variables are meant to be distinct, it would appear that this sharing of values would cause problems. Specifically, if the value of num changed, would variable k change along with it? This cannot hap- pen in this case because the variables refer to integer values, and integer values are immutable.

An immutable value is a value that cannot be changed. Thus, both will continue to refer to the same value until one or both of them is reassigned, as depicted in Figure If no other variable references the memory location of the original value, the memory location is deallocated that is, it is made available for reuse. Finally, in Python the same variable can be associated with values of different type during program execution, as indicated below.

A variable is a name that is associated with a value. The assignment operator, 5, is used to assign values to variables. The value can come from the user by use of the input function introduced in Chapter 1,. In this case, the variable name is assigned the string 'John'. If the user hit return without entering any value, name would be assigned to the empty string ''. All input is returned by the input function as a string type. For the input of numeric values, the response must be converted to the appropriate type.

Python provides built-in type conversion functions int and float for this purpose, as shown below for a gpa calculation program,.

For input of the gpa, the entered value,. Note that the program lines above could be combined as follows,. Built-in functions int and float can be used to convert a string to a numeric type. An identifier is a sequence of one or more characters used to provide a name for a given program element.

Python is case sensitive, thus, Line is different from line. Identifiers may contain letters and digits, but cannot begin with a digit. It should not be used as the first character, however, as identifiers beginning with an underscore have special meaning in Python. Spaces are not allowed as part of an identifier.

This is a common error since some operating systems allow spaces within file names. In programming languages, however, spaces are used to delimit separate distinct syntactic entities. Thus, any identifier containing a space character would be considered two separate identifiers. Examples of valid and invalid identifiers in Python are given in Figure An identifier is a sequence of one or more characters used to name a given program element.

In Python, an identifier may contain letters and digits, but cannot begin with a digit. The special underscore character can also be used. Doing so will result in a syntax error, as demon- strated in the attempted assignment to keyword and below,.

The keywords in Python are listed in Figure To display the keywords, type help in the Python shell, and then type keywords type 'q' to quit. There are other predefined identifiers that can be used as regular identifiers, but should not be. This includes float, int, print, exit, and quit, for example. A simple way to check whether a given identifier is a keyword in Python is given below,.

Yield 5 Doing so will result in a syntax error. This program utilizes the following programming features:. The program is given in Figure Lines 1—2 contain comment lines describing what the program does. The remaining comment lines provide an outline of the basic program sections. Variable tax is used throughout the program in lines 9, 35, and Thus, if the restaurant tax needs to be altered, only this line of the program needs to be changed.

Lines 8—9 display to the user what the program does. The cost of the menu items ordered is obtained from the user in lines 15— Lines 34 and 35 compute the tab, including tax stored in variable tab. Finally, lines 38—41 display the cost of the ordered items, followed by the added restaurant tax and the amount due after deducting the amount of the gift certificate. The customers owe any remaining amount.

A negative amount indicates the amount left on the gift certificate. Built-in function format is used to limit the output to two decimal places. Which of the following are valid assignment statements, in which only variable k has already been assigned a value?

What is the value of variable num after the following assignment statements are executed? Do variables num and k reference the same memory location after the following instructions are executed?

Which of the following are valid identifiers in Python? Which of the following are keywords in Python? Which one of the following is correct for reading and storing an integer value from the user? No, 4. An operator is a symbol that represents an operation that may be performed on one or more oper- ands.

For example, the 1 symbol represents the operation of addition. An operand is a value that a given operator is applied to, such as operands 2 and 3 in the expression 2 1 3.

A unary operator operates on only one operand, such as the negation operator in A binary operator operates on two operands, as with the addition operator. Most operators in programming languages are binary operators.

We look at the arithmetic operators in Python next. An operator is a symbol that represents an operation that may be performed on one or more operands.

Operators that take one operand are called unary operators. Operators that take two operands are called binary operators.



0コメント

  • 1000 / 1000