Needs to be coded in Python. Hello i am working on a project for my computer...

70.2K

Verified Solution

Question

Programming

Needs to be coded in Python.

Hello i am working on a project for my computer programmingcourse and i am having trouble with one part.

The code needs to be able to produce two versions of an outputgiven inputs by the user. for instance.

Here is the code i have to produce the following output. Theinput from the user are num1 num2 and asc which is just asking ifthey want the output to be ascending or descending.

Code with inputs (3, 9, True)

def build_percent_pattern(num1, num2, asc):
s = ''
l = (num2 - num1) + 1
if asc == 'true':
n = 0
s += '\n'
for i in range(l):
for i in range(num1, num2 + 1):
s += '\n' + ' ' * n
n += 1
fact = 0.1 * num1
for i in range(num1, num2 + 1):
s += '{:>.2f} '.format(fact * i)
num1 += 1
return s
else:

This code produces an output such as this.

0.90 1.20 1.50 1.80 2.10 2.40 2.70
1.60 2.00 2.40 2.80 3.20 3.60
2.50 3.00 3.50 4.00 4.50
3.60 4.20 4.80 5.40
4.90 5.60 6.30
6.40 7.20
8.10

I need to somehow manipulate this code to produce an output suchas this.

8.10
6.40 7.20
4.90 5.60 6.30
3.60 4.20 4.80 5.40
2.50 3.00 3.50 4.00 4.50
1.60 2.00 2.40 2.80 3.20 3.60
0.90 1.20 1.50 1.80 2.10 2.40 2.70

The function build_percent_pattern(): needs to be able toproduce both of these outputs based on whether the user choosestrue or false.

If someone could just modify my code for the original output tojust invert it like the second output that is all i really need.Thank you again!

Answer & Explanation Solved by verified expert
4.0 Ratings (761 Votes)
Implemented the code as per the requirement As python isindentation specific you may not get the formatted text whilecopying the codeso Im attaching the    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students