Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write a Python program that reads lines from an input file called data.txt. Each line consists of a keyword, followed by a sequence of numbers separated by commas. The keyword UP indicates that the number should be sorted in ascending order, while the keyword DOWN indicates that the number should be sorted in descending order. The program sorts the numbers and saves them in the file called sorted.txt. For example, if the data.txt file contains
UP 25 35, 30, 40, 30
DOWN 20, 30, 25, 25 DOWN 35, 45, 40, 15, 16, 18
The file sorted.txt will contain
25 30 30 35 40
30 25 25 20
45 40 35 18 16 15
Instructions
Write a program that uses an initializer list to store the following set of numbers in an array named nums. Then, print the array.

14 36 31 -2 11 -6
using recursion and the is_divisible function, Your program may assume that both arguments to is_power are positive integers. Note that the only positive integer that is a power of "1" is "1" itself.

After writing your is_power function, include the following test cases in your script to exercise the function and print the results:

print("is_power(10, 2) returns: ", is_power(10, 2))
print("is_power(27, 3) returns: ", is_power(27, 3))
print("is_power(1, 1) returns: ", is_power(1, 1))
print("is_power(10, 1) returns: ", is_power(10, 1))
print("is_power(3, 3) returns: ", is_power(3, 3))
("Debugging") lists three possibilities to consider if a function is not working.

Describe each possibility in your own words.

Define "precondition" and "postcondition" as part of your description.

Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.
("Debugging") lists three possibilities to consider if a function is not working.

Describe each possibility in your own words.

Define "precondition" and "postcondition" as part of your description.

Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.
10. Adding certain numbers to their reversals sometimes produces a palindromic number. For
instance, 241 + 142 = 383. Sometimes, we have to repeat the process. For instance, 84 + 48 =
132 and 132 + 231 = 363. Write a program that finds both two-digit numbers for which this
process must be repeated more than 20 times to obtain a palindromic number.
Secondhand Rose Resale Shop is having a seven-day sale during which the price of any unsold item drops 10 percent each day. For example, an item that costs $10.00 on the first day costs 10 percent less, or 9.00, on the second day. On the third day, the same item is 10 percent less than $9.00, or $8.10. Design an application that allows a user to input a price until an appropriate sentinel value is entered. Output is the price of each item on each day, one through seven.
Define "precondition" and "postcondition" as part of your description.

Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.
Create your own example of each possibility in Python code. List the code for each example, along with sample output from trying to run it.
Topic: Files
You have to perform file operations in different modes using python code on text file.
you can use any piece of information like groceries, books inventory, bank transactions and build your scenario on that, use text files for putting in the data.
Lab scenario:
1. You will have to perform read, write, append modes on your text file. (35 points, each mode 10 points).
2. Use all the possible functions for read and write.
3. Create a scenario, use “with” for manipulating the file and mention what your code is
intended to do. (15 points).
Submission:
Three files have to be submitted
1. Text file having your data (EC4_lastname.txt)
2. Word document what explain your data and what each mode is doing.
(EC4_lastname.doc)
3. Python file where you have your code. (EC4_lastname.py).
LATEST TUTORIALS
APPROVED BY CLIENTS