font size
Increasing the font size is not possible for terminal output programs (with print): This is part of your terminal settings - which is a program that your Python program, and the Python language executable itself, only uses, it is not "owner" of the terminal.
Programs that interact with "world" with print and input only come three "data streams", which are the (pseudo) sys.stdin, sys.stdout and sys.stderr files - all print does is write characters in those files.
In operating systems that are not Windows, or, with some configuration in Windows, some strings of characters allow the configuration of front and background colors, as well as text positioning on the terminals - (see https://en.wikipedia.org/wiki/ANSI_escape_code ), but there are no sequences to change the font size.
If you want a more user-friendly output, perhaps as part of the "finish" to deliver an application for use by other users, the only output is to create a program that uses another type of interface than the terminal. It could be a program with a web interface - in this case you could use a micro-framework like the "Flask", or a program that works with a graphical window directly - in this case you can use the "Tkinter", that accompanies the installation of Python in Windows, or a graphical Toolkit like the "Qt".
Limit decimal places
This is simpler - the problem is that you are using the print
in a very rudimentary way - separating everything you want to print by ",", and delimiting each substring by quotation marks.
The most common use is to use Python’s string formatting capabilities and compose a single string with the already formatted text and data that you want to print, and then call the print
with that string. In case the program has been changed to a graphical window, or an output to the Web, the same string can be used, only it is not passed to print.
Starting from Python 3.6, the recommended way to compose strings with text and formatted data is with the use of "f-strings" - are strings that have the prefix f"
or f'
- that is, the letter "f" before the opening quotation marks. Inside these strings, any expression that appears between keys ({ }
) is treated as Python code (for example, a variable name is replaced by its value). And even more, before closing the key, after the desired expression one can make use of a "mini formatting language", which allows things like justifying the text or controlling the number of decimals of a number.
The mini-language is complicated, but going to the part that matters - you can write your print
thus:
print(f'Coeficiente de troca de calor por convecção: {hf:0.04f} W/m² K')
Thus, as explained - within the same string, started with the prefix f
, the name hf
used inside the keys will be exchanged for the variable value, and the sequence :0.04f
indicates that the value must be treated as a floating point, and 4 numbers must be printed after the decimal point, filled with "0" if there are fewer decimal places than that.
The full reference of the formatting mini-language is the one documented for the method format
of strings (which should be used in versions prior to 3.6 of Python, which did not yet have the f-strings) - https://docs.python.org/3/library/string.html#format-string-syntax
(I also switched the 2 for the "²" character - it will work on most terminals - but maybe not on the standard Windows terminal).
Jupyter notebook
In simple use, the Jupyter notebook emulates the behavior of sys.stdin, sys.sdout, so that the print and input work. Using the normal Python functions it is not possible to have more control over the output than in a terminal. The bigger difference is that unlike a Windows terminal, it allows some ANSI sequences, in particular for color change. (Short example is in the comment below).
However the notebook jupyter has some categories of objects that allow more control of the output, and interaction with the direct browser yes - that could limit the development of a complete graphical application inside the notebook.
However, doing this is a couple of orders of magnitude more complicated than simply using "print" and "input". The most direct way seems to be to create an object that will be an output "widget", and using this "widget" in a command with
from Python, you can redirect the print output to it. The Widget on the other hand can have some of the custom printing features - it can have border and color of text specified in CSS. However, I was unable to amend the font size: the "font-size" property is ignored in the widget layout.
from ipywidgets import widgets
from IPython.display import display
out = widgets.Output(layout={"color":"red", 'border': '1px solid blue', 'font-size': '200%'})
display(out)
with(out):
print(f"Alô mundo. Formatando número: {3.210002:0.02f}")
Documentation of widgets:
https://ipywidgets.readthedocs.io/en/stable/examples/Output%20Widget.html
https://stackoverflow.com/questions/2075128/python-print-all-floats-to-2-decimal-places-in-output I believe this answers your question to the decimal places.
– SylvioT