Edit: Computing Science with Python (Arithmetic Formatter)

Tell us what’s happening:
On Mean-Variance-Standard Deviation Calculator:

Hello,

I got one operation up and running, not esp. concerned on the functionality of it so far (self-alignment of it all when printing is good too) , but rather on how to print side by side ( vertically) just one more block for another operation.

Should I change the approach on how to print these rather horizontally? Maybe creating different lists to separate 1st terms, 2nd terms with operation sign, dashes and then results ? Any clue on this?

chop=[‘4’ , ‘-’ , ‘5939’]
chop_int1=int(chop[0])
chop_int2=int(chop[2])
max_chop=max(len(chop[0]), len(chop[2]))
dashes= max_chop+2
answer= chop_int1-chop_int2
print(f"{chop_int1 : > {dashes}}“)
print(f”{‘-’}{chop_int2 : > {dashes-1}}“)
print(f”{‘-’*dashes : <{dashes}}“)
print(f”{answer : >{dashes}}")

I’ve just trimmed the portion of the code where the printing happens.

Cheers,

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator

Link to the challenge:

Edit
PS: This project belongs to Scientific Computing with Python and the name is Arithmetic Formatter:

You won’t print directly like this, but rather you should build a string line by line and return the full string at the end.

outputstring = problem1[0] + spaces + problem2[0]

This would build the first line with the 1st term of 2 different problems

outputstring += \n + problem1[1] + problem1[2] + spaces + problem2[1] + problem2[2]

add a newline, and your second line of operators and 2nd term of each problem.

at the end:

return outputstring

Thanks pkdvalis. I can use some time to understand technically what you meant -esp. the 2nd code line- but this sounds like a ‘printing-horizontally’ approach

Not sure if I explained it well, but it will make sense when you’re coding it, if you think of the output line by line, and not problem by problem.

outputstring = problem1[0] + spaces + problem2[0]

the first statement result:
outputstring = f'4 10'

4 10

outputstring += \n + problem1[1] + problem1[2] + spaces + problem2[1] + problem2[2]

second:
outputstring = f'4 10\n+ 5 -3'

4 10
+ 5 - 3

Many thanks pkdvalis. I think I understood the main idea you intended to mean.
I just need time to sit down and brawl with Python. I’ve attached a scheme of what I intend to do. The final layout of the operations should adapt to the variable input ( except for the fixed 4 between operations).

Was that sort of what you meant?

2 Likes

This looks like a good guide. Now you just need to format it as a dot matrix printer would print it! :printer:

Many thanks pkdvalis! You were right: the printing looks to run good after having tried to make it fail for several times. I’ll focus on the ‘Too many problems’ logic as well as putting all together -trying to minimize it- the rest of the arithmetic code :slightly_smiling_face:
Cheers~

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.