tunnid = int(input("Sisestage oma töötundide arv ühes nädalas: "))
tasu = int(input("Sisestage oma tunnitasu: "))
if tunnid <= 40:
print("Teie nädalapalk on " + str(tunnid*tasu))
else:
print("Teie nädalapalk on " + str(tunnid*tasu*1.5))
If i multiply 60*10 as else i should get 900, but program gives me 900.0 So my quiestion is, how to remove this .0 from the answer, what do i have to change in my code?
p.s Im just a beginner so don't judge please :)
Just convert the number with int
:
print('Teie nädalapalk on {}'.format(int(tunnid * tasu * 1.5)))
Alternatively, you can use the format
mini-language:
print('Teie nädalapalk on {:.0f}'.format(tunnid * tasu * 1.5))
The .0f
tells the number to be truncated to 0 decimals (i.e. integer representation)
Simplest way will be to type-cast the float
value to int
. For example:
>>> x = 100.0
>>> x = int(x)
>>> x
100
Hence, in your code you should do:
print("Teie nädalapalk on " + str(int(tunnid*tasu)))
# Note: "str(tunnid*tasu)" replaced with "str(int(tunnid*tasu))"
>>> num = 900.0 # tunnid * tasu * 1.5
>>> int(num) if num == int(num) else num
900
>>> num = 900.6 # tunnid * tasu * 1.5
>>> int(num) if num == int(num) else num
900.6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With