Need help on the 'if and else'structure

I created two structures 'if and else' to make the program write to the user using the plural correctly and as you can see below, I created two variables within the structures to assign the plural that the program decides. Is there any way to assign the values to two variables within a single structure? Do something like:

if m > 1: b = metros, c = centimetros? 

Since I do not know what value the user will provide, I decided to declare the variable as float, but as float are the real numbers, if the user enters an integer, the result will be with .0 at the end. For this not to happen, I would need to create another structure if and else?

I'm using Python 3.7 and the PyCharm IDE.

Make a program that converts meters to centimeters.

m = float(input('Insira a medida em metros: '))

b = 'd'

if m > 1:
    b = 'metros'

else:
    b = 'metro'

if m > 1:
    d = 'equivalem'

else:
    d = 'equivale'


c = m * 100

print(f'{m} {b} {d} a {c} centimetros')  
Author: Maniero, 2019-09-29

1 answers

Can do yes:

if m > 1:
    b = 'metros'
    d = 'equivalem'
else:
    b = 'metro'
    d = 'equivale'

If you are going to use the words in sequence, then you don't even have to keep two variables:

if m > 1:
    b = 'metros equivalem'
else:
    b = 'metro equivale'

I put on GitHub for future reference .

I think it would be better to use more significant variable names.

Ever thought that one can Type 0? What solution Do you want to give to this? Will you pluralize?

You can do this in a more modern and correct way, but I preferred not to introduce these things to you now.

Rounding has already been answered in How to "round" a float in Python?.

 4
Author: Maniero, 2019-10-01 12:50:02