0

i'm trying to get my outputs to align. I used the tab function. But the prof says: "The code for this must not use tabs or spaces for alignment, but should instead use formatted output. "

I tried using format('10.2f') to indicate the number of spaces I want and where to round, but i keep getting a syntax error.

I cant use str() because we havent learned those yet in the class. we've only covered tabs, spaces, and left, right, and center adjustments

Problemo dos: i need to round subtotal to the nearest penny before proceeding and then round tax to the nearest penny before proceeding. but then i do

format(Subtotal= subPot + petPri + bagPri, '.1f')

i get

positional argument follows keyword argument

and when I try

Tax = Subtotal * TAX_RATE, format(Subtotal, '.1f'), 

I get:

unsupported operand type(s) for +: 'float' and 'tuple'

This is my code:

# Calculations for overall total price
Subtotal = subPot + petPri + bagPri
Tax = Subtotal * TAX_RATE
TOTAL = Subtotal + Tax


# Output
print ("-----------------------------------------------")
print ("Supplies and Pricing for Order", userOrder,)
print ()
print ("Number of small pots: \t",     int(smlPot),)
print ("Number of medium pots: \t",    int(medPot),)
print ("Number of large pots: \t",     int(larPot),)
print ()
print ("Petunias:",                int(totPet), "plants")
print ("Potting soil:",            math.ceil(totBag), "bags")
print ()
print ("Subtotal\t""$""\t",            format(Subtotal, ',.2f'))
print ("Tax\t\t""$""\t",               format(Tax, ',.2f'))
print ("TOTAL\t\t""$""\t" ,            format(TOTAL, ',.2f'))
print ("-----------------------------------------------")

I want to align everything without using tab or spaces. It should look like this:

--------------------------------------------------
Supplies and Pricing for Order 1234
Number of small pots:        5
Number of medium pots:       6
Number of large pots:        7

Petunias:                101 plants
Potting soil:              4 bags

Subtotal    $   123.45
Tax         $   18.56
TOTAL       $   234.78
--------------------------------------------------
j.davis
  • 5
  • 4

1 Answers1

0

I assume you are using python 3.x. As you said you can't use tabs and spaces what you can do is using methods for string. For example, there are many functions such as ljust(), rjust(), center(), also you can use round() function. You have str() function so that to use above string methods first round your number, then convert it to string then apply these methods. For what they exactly do and what arguments they take, you can go for their documentation. They are methods for strings.Also,end='' is a separator which says what to print after printing the string. By default it is a new line, here I have used end=''.I have taken all the values to 0. I guess now you can figure out what to do. If not, do tell me. Also, I have already edited your full code, if you are not able to figure out from here, you can tell me. I have done an edit to a part of your code and you can see what the output is. Below is the code:

subPotm, petPri, bagPri = 0, 0, 0
smlPot, medPot, larPot = 0, 0, 0
subPot = 0
TAX_RATE = 0
userOrder = 0    

Subtotal = subPot + petPri + bagPri
Tax = Subtotal * TAX_RATE
TOTAL = Subtotal + Tax


print ("-----------------------------------------------")
print ("Supplies and Pricing for Order".ljust(30), end='')
print (userOrder)
print ()
print ("Number of small pots:".ljust(30), end='')
print (smlPot)
print ("Number of medium pots:".ljust(30), end='')    
print (medPot)
GadaaDhaariGeek
  • 971
  • 1
  • 14
  • 33