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~
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
803 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
555 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
561 PHP ssh2_scp_send fails to send files as intended
555 Who developed the "avformat-59.dll" that comes with FFmpeg?
564 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.