### Description

## PYTHON ENTIRE COURSE HELP

Python is powerful… and fast;

plays well with others;

runs everywhere;

is friendly & easy to learn;

is Open

Python can be easy to pick up whether you’re a first time programmer or you’re experienced with other languages

# 25.7 LAB: Output values below an amount in python

Write a program that first gets a list of integers from input. The last value of the input represents a threshold, Output all integers less than or equal to that threshold value. Do not include the threshold value in the output.

For simplicity, follow each number output by a comma, including the last one

**Ex:**

If the input is

50 60 140 200 75 100

the output is:

50, 60, 75,

## PYTHON ENTIRE COURSE HELP

# Implement Square and Sum of the Numbers in Python

Write a program that will accept a list of numbers from the user. Write and test two functions to meet the following specifications:

- squareEach(nums), nums is a list of numbers, returns a list of the square of each number in the list
- sumList(nums), nums is a list of numbers, returns the sum of the numbers in the list

Print the original list, the list of squared values and the sum of the list.

## PYTHON ENTIRE COURSE HELP

# The Sieve of Eratosthenes Implementation in Python

The Sieve of Eratosthenes is an elegant algorithm for finding all the prime numbers up to some limit n. The basic idea is to first create a list of numbers from 2 to n. The first number is removed from the list, and announced as prime, and all multiples of this number is removed up to n are removed from the list. This process continues until the list is empty.

For example, if you wanted to find all the prime numbers up to 10, the list would contain 2, 3, 4, 5, 6, 7, 8, 9, 10. The 2 is removed and announced to be prime and 4, 6, 8, and 10 are removed since they are multiples of 2. That leaves 3, 5, 7, 9., repeat the process until the list is empty

Write a program that prompts a user for n and then uses the sieve algorithm to find all the prime numbers less than or equal to n

## PYTHON ENTIRE COURSE HELP

# Caesar Cipher implementation in Python

A Caesar cipher is a simple substitution cipher based on the idea of shifting each letter of the plaintext message a fixed number (called the key) of positions in the alphabet.

Write a program that can encode and decode Caesar ciphers. The input to the program will be a string of plaintext and the value of the key. The output will be an encoded message where each character in the original message is replaced by shifting it key characters in the Unicode character set.

One problem how do you deal with the case when we drop off the end of the alphabet. A true Caesar cipher does the shifting in a circular fashion where the next character after “z” is “a”.

encode the following sentence with a shift of 4 and then decode the cypher text back into the original message

Message – the ships sail at midnight

## PYTHON ENTIRE COURSE HELP

# Python Assignment Sum Product Average of the Numbers

Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing input. After the user presses the enter key, the program should print the sum of the numbers, the product of the numbers, and the average of the numbers.

Run your program with the following inputs:

1, 2, 3, 4, 5, 6, 7, 8

2,24,11,1,4,10

## PYTHON ENTIRE COURSE HELP

# Implement Insertion Sort, an improved Merge Sort, and an improved Quick Sort

**Program and Functions**

Create a function repository called sorts.[x] where [x] is the appropriate file extension for your language choice. If you decide to use a language other than Java, Python, C++, or C, you must schedule a time to show me your running code.

If needed, your functions may include the size of your array, and you may name your variables as you like. Many of the functions we reviewed in class indexed arrays from 1 to n, so make sure you double check all of your indices! Each of the three sorting functions should alter the array sent.

- insertionSort(array S) – In-place insertion sorts the array from index low to index high (inclusive). You will also need a helper method version of this sort that accepts indices.
- merge(array S, array T) – Merges the two sorted arrays so the result is sorted. Returns the result.
- mergeSort(array S) – Merge sorts the array, but switches to insertion sort when the array is smaller than 16 items. Although the sort is not in-place, the correct sort is copied back into the original array.
- partition(array S, low, high) – Partitions the items in the array from index low to index high (inclusive) around the pivot, which is the median value from the three items at index low, high, and in-between. Returns the location of the pivot.

**Note:** The version of partition given in the book is a variation of the Lomuto partition scheme. Although it looks shorter and simpler than the one given in class (a variation of the Hoare partition scheme), it performs more slowly because it requires more exchanges. You may choose which scheme you use (just make sure you choose the median each time – if you don’t you will likely run out of stack space for quicksort when you have more than 1000 items in your array), and make sure you mention your choice in the write-up.

quickSort(array S) – “In-place” quick sorts the array, but switches to insertion sort when the portion of the array that is being sorted is smaller than 16 items. Note that this method does not require indices, so you will need a helper method.

All functions above should be public, and any extra functions you use should be private (indicate by underscores if you code in Python).

**Testing**

Write a tester file that tests each of the sorts with a variety of array sizes that have a variety of presortedness: completely random, mostly sorted, and already sorted.

- How small should you test?
- How large should you test? How would you create a mostly sorted array and how would you decide that it’s mostly sorted?

Create several copies of the same array at each size and presortedness, and time each of your sorting functions. And of course, before you do the above testing, make sure you also test for correctness. Example array for testing correctness:

[1, 2, 3,7, 9, 4, 5, 12, 13, 14, 23, 27, 24, 25, -1, -2, -3, 3, 3, 3, ]

**Write up**

Your submission should include a write-up for your project, in LATEX containing the following sections:

- Introduction – A description of your project.
- Methodology – A description of each of your sorting functions that would be understandable by someone who does not know about these sorts, a description of improvements made over the original sort, and a description of your use of helper methods.
- Results – How you chose your test sizes and what determined “mostly” sorted, tables/graphs containing your results, an overall description of your results, and some general analysis of why you got those results.

## PYTHON ENTIRE COURSE HELP

# Create a Class Called pathGraph Implement Shortest Path Algorithm

Create a class called pathGraph and save it in a file called pathGraph.[x] where [x] is the appropriate file extension for your language choice. If you decide to use a language other than Java, Python, C++, or C, you must schedule a time to show me your running code. A pathGraph is an undirected, weighted graph with positive weights. The pathGraph should have an instance variable containing the weighted adjacency matrix and any other instance variables you feel it needs.

Your class should have the following methods:

- constructor – Receives a file name, as a string, of a file containing the weighted adjacency matrix. The first line of the file contains n the number of vertices, indexed from 0 to n-1. The rest contains the weighted adjacency matrix with weights between each edge or -1 if the edge does not exist. You do not have to store the nonexistent edges as -1, but, whatever way you store them, you will have to be clever about your nonexistent edges for each algorithm, i.e., you’ll have to be careful whenever you use your weighted adjacency matrix.
- getEdge(int i, int k) – Returns the length of the edge between i and k or -1 if it does not exist. getSize() – Returns the number of vertices in the graph.
- floyd() – Uses the Floyd-Warshall algorithm and returns D, the matrix containing the lengths of the shortest paths between all vertices in the graph. Make the necessary changes to the algorithm to account for your storage of nonexistent edges.
- dijkstra(int x) – Uses Dijksta’s Algorithm and returns P, an array containing the prior vertex on the shortest path from x to i for each vertex i in the graph, i.e., P[i] = y, then the shortest path from x to i ends in the edge (y,i). Make the necessary changes to the algorithm to account for your storage of nonexistent edges (hint: you may have to separate vertices you are no longer considering and vertices whose known shortest path is currentlyinfinity, plus consider how you are storing your nonexistent edges in the weighted adjacency matrix).
- Bonus: findpath(int x, int y) – returns s, an array containing the shortest path from x to y in the graph. For example, if s = [1;4;2;5;0], then the shortest path from 1 to 0 goes through vertices 4, 2, and 5, in that order.

All methods above should be public, and any extra methods you use should be private (indicate by underscores if you code in Python). Write a tester file that creates pathGraph instances and tests each of your methods with those instances. There is an example with expected results at the end of this project description. Create another graph of your choosing (it’s fine to get ideas from the book/online), use 5-10 vertices, store it appropriately in a text file, and test your code with that graph. Include the results in your write-up as well as an image of what the graph would look like. It’s often easier to start with the

image/design.

## PYTHON ENTIRE COURSE HELP

# Fundamentals of Python Chapter 9 Project 1 2

**1. **Write a GUI-based program that implements the bouncy program example discussed in Section 9.1.

**2. **Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. These components should be arranged in a grid where the labels occupy the first row and the corresponding fields occupy the second row. At start-up, the Fahrenheit field should contain 32.0, and the Celsius field should contain 0.0. The third row in the window contains two command buttons, labeled and When the user presses the first button, the program should use the data in the Fahrenheit field to compute the Celsius value, which should then be output to the Celsius field. The second button should perform the inverse function.

## PYTHON ENTIRE COURSE HELP

# Fundamentals of Python Chapter 8 Project 1 2 3

These projects must be done in the latest version of IDLE: Also, please label and add brief comments to lines of code.

- Add methods to the Student class that compare two Student objects. One method should test for equality. The other methods should support the other possible comparisons. In each case, the method returns the result of the comparison of the two students’ names.
- This project assumes that you have completed Project 1. Place several Student objects into a list and shuffle it. Then run the sort method with this list and display all of the students’ information.
- The str method of the Bank class returns a string containing the accounts in random order. Design and implement a change that causes the accounts to be placed in the string by order of name. (Hint: You will also have to define some methods in the SavingsAccount class.)

## PYTHON ENTIRE COURSE HELP

# Fundamentals of Python Chapter 6 Project 6 7 8 9

These projects must be done in the latest version of IDLE:

**6. **Add a command to this chapter’s case study program that allows the user to view the contents of a file in the current working directory. When the command is selected, the program should display a list of filenames and a prompt for the name of the file to be viewed. Be sure to include error recovery.

**7. **Write a recursive function that expects a pathname as an argument. The pathname can be either the name of a file or the name of a directory. If the pathname refers to a file, its name is displayed, followed by its contents. Otherwise, if the pathname refers to a directory, the function is applied to each name in the directory. Test this function in a new program.

**8. **Lee has discovered what he thinks is a clever recursive strategy for printing the elements in a sequence (string, tuple, or list). He reasons that he can get at the first element in a sequence using the 0 index, and he can obtain a sequence of the rest of the elements by slicing from index 1. This strategy is realized in a function that expects just the sequence as an argument. If the sequence is not empty, the first element in the sequence is printed and then a recursive call is executed. On each recursive call, the sequence argument is sliced using the range 1:. Here is Lee’s function definition:

def printAll(seq):

if seq:

print seq[0]

printAll(seq[1:])

Write a script that tests this function and add code to trace the argument on each call. Does this function work as expected? If so, explain how it actually works, and describe any hidden costs in running it.

**9. **Write a program that computes and prints the average of the numbers in a text file. You should make use of two higher-order functions to simplify the design.

## PYTHON ENTIRE COURSE HELP

# Newton’s Method for Approximating Square Roots

These projects must be done in the latest version of IDLE:

- Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key.
- Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of the square root should be passed as a second argument to the function.)
- Elena complains that the recursive newton function in Project 2 includes an extra argument for the estimate. The function’s users should not have to provide this value, which is always the same, when they call this function. Modify the definition of the function so that it uses a keyword parameter with the appropriate default value for this argument, and call the function without a second argument to demonstrate that it solves this problem.
- Restructure Newton’s method (Case Study 3.6) by decomposing it into three cooperating functions. The newton function can use either the recursive strategy of Project 1 or the iterative strategy of Case Study 3.6. The task of testing for the limit is assigned to a function named limitReached, whereas the task of computing a new approximation is assigned to a function named improveEstimate. Each function expects the relevant arguments and returns an appropriate value.
- A list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. Define a predicate isSorted that expects a list as an argument and returns True if the list is sorted, or returns False otherwise. (Hint: For a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return False if the first item in a pair is greater.)

## PYTHON ENTIRE COURSE HELP

# Python Assignments Stats Read File and Sentence Generator

These projects must be done in the latest version of IDLE:

- A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set of numbers, as defined in Section 5.4. Define these functions in a module named stats.py. Also include a function named mean, which computes the average of a set of numbers. Each function should expect a list of numbers as an argument and return a single number. Each function should return 0 if the list is empty. Include a main function that tests the three statistical functions with a given list.
- Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number.
- Modify the sentence-generator program of Case Study 5.3 (Link Here: Fundamentals of Python: First Programs) so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt, verbs.txt, articles.txt, and prepositions.txt. (Hint: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list to a tuple and return this tuple. Call the function with an actual filename to initialize each of the four variables for the vocabulary.)

## PYTHON ENTIRE COURSE HELP

# Python Assignments Caesar Cipher

These projects must be done in the latest version of IDLE:

- Write a script that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher. The script should work for any printable characters.
- Write a script that inputs a line of encrypted text and a distance value and outputs plaintext using a Caesar cipher. The script should work for any printable characters.
- Modify the scripts of Projects 1 and 2 to encrypt and decrypt entire files of text.

## PYTHON ENTIRE COURSE HELP

# Python Assignments Credit Plan and Series Numbers

These projects must be done in the latest version of IDLE:

- Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing inputs.

After the user presses the enter key, the program should print the sum of the numbers and their average. - The credit plan at TidBit Computer Store specifies a 10% down payment and an annual interest rate of 12%. Monthly payments are 5% of the listed purchase price, minus the down payment.

Write a program that takes the purchase price as input. The program should display a table, with appropriate headers, of a payment schedule for the lifetime of the loan. Each row of the table should contain the following items:- the month number (beginning with 1)
- the current total balance owed
- the interest owed for that month
- the amount of principal owed for that month
- the payment for that month
- the balance remaining after payment
- The amount of interest for a month is equal to balance * rate / 12. The amount of principal for a month is equal to the monthly payment minus the interest owed.

## PYTHON ENTIRE COURSE HELP

# Python Assignments Triangle and Guessing Number

These projects must be done in the latest version of IDLE:

- Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle.
- Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle.

Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides. - Modify the guessing-game program of Section 3.5, listed below, so that the user thinks of a number that the computer must guess. The computer must make no more than the minimum number of guesses.(Code is as follows)1234567891011121314
`import random`

`smaller = int(input(`

`"Enter the smaller number: "`

`))`

`larger = int(input(`

`"Enter the larger number: "`

`))`

`myNumber = random.randit(smaller, larger)`

`count`

`= 0`

`while`

`True:`

`count`

`+= 1`

`if`

`userNumber &lt; myNumber:`

`print`

`(`

`"Too small"`

`)`

`elif userNumber &gt; myNumber:`

`print`

`(`

`"Too large"`

`)`

`else`

`:`

`print`

`(`

`"Congratulations! You've got it in"`

`,`

`count`

`,`

`"tries!"`

`)`

`break`