I have a question about matching Python numbers!!!

Asked 2 years ago, Updated 2 years ago, 12 views

I have the last question of the Python assignment, so I'm looking for a place to ask questions and asking questions here.

I wrote a program that outputs calculated results using repetitive statements as shown in the picture In the first example, the numbers are aligned In the second example, the first line 50 and the resulting value 18.9191 do not match.

Is the use of format wrong? I tried to adjust it with \t and spacing, but it didn't work. Please help me.

Only one image was uploaded, so I wrote down the code I made in the answer. Please help me once~

python

2022-09-21 22:53

1 Answers

while True:
    carbon=float(input('Quantity of carbon dioxide (moles) > '))
    if carbon>0:
           break;
while True:
    tem=int(input('Temperature (Kelvin) > '))
    if tem>0:
      break;

while True:
    iniv=int(input('Initiail volume (mililiters) > '))
    if iniv>0:
      break;

while True:
    fvol=int(input('Final volume (mililiters) > '))
    if fvol>0:
      break;

while True:
      vinc=int(input('Volume Incerment (mililiters) > '))
      if vinc>0:
       break;
#I wrote print('/n') for two lines of space
print('\n')
print('\n')
#Format was used to adjust the number of digits in the output value.
print('{:.4f} moles of dioxide in {} kelvin'.format(carbon,tem))
print('\n')

#Expresses volume and pressure. I did spacing using \t.
print('Volume(ml)\tPressure(atm)')
#We divided it by 1000 because we need to change iniv and vinc in liters to calculate.
V=iniv/1000
inc=vinc/1000
running=True
while running:       
#Carbon was put in mole units from the beginning, and the temperature was put in K, so I calculated it according to the calculation formula in question.
      p=(carbon*0.08206*tem/(V-(0.0427*carbon))-(3.592*carbon**2)/V**2)
      print('        {:.0f}  \t     {:.4f}'.format(int(V*1000),p))
      V+=inc
      if V>fvol/1000+0.0005:
          running=False



2022-09-21 22:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.