QuestionQuestion

Transcribed TextTranscribed Text

Programming Exercise Chapter 2: After Completing the Chapter 2 Readings and Activities; Work on the Programming Exercise P2.4 found on page 80 of the textbook (Prompt for two Integers and Print). See the attached volume2.py program from Chapter 2 for reference and your use on prompting for numeric input and displaying output. P2.4 Write a program that prompts the user for two integers and then prints The sum The difference The product The average The distance (absolute value of the difference) The maximum (the larger of the two) The minimum (the smaller of the two) Hint: Python defines max and min functions that accept a sequence of values, each separated with a comma. Programming Exercise Chapter 3: After Completing the Chapter 3 Readings and Activities; Work on the Programming Exercise P3.1 found on page 151 of the textbook (Negative, Zero or Positive). P3.1 Write a program that reads an integer and prints whether it is negative, zero, or positive. After Completing the Chapter 4 Readings and Activities; Work on the Programming Exercise P4.6 found on page 230 of the textbook (Translate pseudo code). See section 4.8 of Chapter 4 for processing strings and the use of a while loop with if and elif statements. P4.6 Translate the following pseudocode for finding the minimum value from a set inputs into a Python program. Set a Boolean variable "first" to true. While another value has been read successfully If first is true Set the minimum to the value. Set first to false. Else if the value is less than the minimum Set the minimum to the value. bluode Print the minimum. 100 After Completing the Chapter 5 Readings and Activities; Work on the Programming Exercise P5.3 found on page 305 of the textbook (Write Function first, last and digits). P5.3 Write the following functions and provide a program to test them. a. def firstDigit(n) (returning the first digit of the argument) b. def lastDigit(n) (returning the last digit of the argument) c. def digits(n) (returning the number of digits in the argument) For example, firstDigit (1729) is 1, lastDigit (1729) is 9, and digits (1729) is 4. Complete the following Review Exercises on pages 369 and 370 of the class textbook: R6.1, R6.2, R6.3, R6.4, and R6.5 R6.1 Given the list values = [], write code that fills the list with each set of numbers below. a. 1 2 3 4 5 6 7 8 9 10 b.0 2 4 6 8 10 12 14 16 18 20 4 9 16 25 36 49 64 81 100 c. 1 d.0 e. 1 4 9 16 9 7 4 9 11 f. 0 1 0 1 0 1 0 1 0 1 g.0 1 2 3 4 1 2 3 4 R6.2 Consider the following list: = [1, 2, 3, 4, 5, 4, 3, 2, 1, 0] What a is the value of total after each of the following loops complete? f. total - 0 a. total = 0 for i in range (9, -1, -1) : for i in range (10) : total - total + a[i] total - total + a[i] b. total = 0 g. total - 0 for i in range (0, 10, 2) : for 1 in range (9, - -1, -2) : total - total + a[i] total = total + a[i] c. total = 0 h. total - 0 for i in range (1, 10, 2) : for i in range (0, 10) : total = total + a[i] total - - d. total - 0 - for i in range (2, 11) : total = total + a[i] e. total = 0 i - 1 while i < 10 : total - total + a[i] i - 2 * i R6.3 Describe three different ways of making a copy of a list that don't involve the list function. R6.4 Consider the following list: a = [1, 2, 3, 4, 5, 4, 3, 2, 1, 0] What are the contents of the list a after each of the following loops complete? (For each part, assume the list a contains the original list of values.) a. for i in range (1, 10) : e. for i in range (1, 10) : a[i]=a[i-1] - a - a [i] + a[i - 1] b. for i in range (9, 0, -1) : f. for i in range (1, 10, 2) : a[i] - a[i - 1] a[i] = 0 c. for i in range (9) : g. for i in range (5) : 101 a[i] - a[i + 1] a[i + 5] - a[i] d. for i in range (8, -8, -1) : h. for i in range (1, 5) : a[i] = a[i + 1] a[i] - a[9 - i] ... R6.5 Write a loop that fills a list values with ten random numbers between 1 and 100. Write code for two nested loops that fill values with ten different random numbers between 1 and 100. Complete the following Review Exercises on pages 442 and 443 of the class textbook: R7.1, R7.2, R7.3, R7.4, R7.5, R7.6, R7.7, R7.8, R7.9 and R7.10 R7.1 What happens if you try to open a file for reading that doesn't exist? What happens if you try to open a file for writing that doesn't exist? R7.2 What happens if you try to open a file for writing, but the file or device is write- protected (sometimes called read-only)? Try it out with a short test program. R7.3 How do you open a file whose name contains a backslash, like c:\temp\output.dat? R7.4 If a program Woozle is started with the command python woozle.py -Dname=piglet -Ieeyore -V heff. txt a.txt lump. txt what are the values of argv[0], argv[1], and so on? R7.5 What is the difference between raising an exception and handling an exception? R7.6 When your program executes a raise statement, which statement is executed next? . . R7.7 What happens if an exception does not have a matching except clause? . R7.8 What can your program do with the exception object that an except clause receives? R7.9 What is the difference between sequential access and random access? R7.10 What is the difference between a text file and a binary file?

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

Source code:
number1 = int(input(“Enter first number:”))
number2 = int(input(“Enter second number:”))
print(“Sum:”, number1+number2)
print(“Difference:”, number1-number2)
print(“Product:”, number1*number2)
print(“Average:”, 0.5*(number1+number2))
print(“Distance:”, abs(number1-number2))
print(“Maximum:”, max(number1, number2))
print(“Minimum:”, min(number1, number2))...

By purchasing this solution you'll be able to access the following files:
Solution1.pdf, Solution2.pdf, Solution3.pdf, Solution4.pdf, Solution5.pdf, Solution6.pdf and Solution7.pdf.

$75.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats