+ 1
Tried using the formatting method for these variables but it ain't working out
dividend = int(input('Enter your dividend = ')) divisor = int(input('Enter your divisor =')) print('{} \ {} =' .format(dividend\divisor))
3 Answers
+ 7
i would prefer to use the f-string formatting which is much easyer to understand:
dividend = int(input('Enter your dividend = '))
divisor = int(input('Enter your divisor ='))
print(f'{dividend} / {divisor} = {dividend / divisor:.4}')
The only thing that has to be explained is
{dividend / divisor:.4}') :.4 is a formatting of the output of decimals
+ 2
Well, it's pretty unclear what you tried to do with all those backslashes...
I suppose it should be something like this:
print("{} / {} = {}".format(dividend, divisor, dividend / divisor))
+ 1
'\' is an escape character, if you want to display a backslash you have type it twice. However division uses '/'.
Try:
print("{0} \\ {1} =".format(dividend, divisor))
Example:
dividend = 10
divisor = 5
result = dividend/divisor
print("{0}\\{1} = {2}".format(dividend, divisor, result))
Outputs:
10\5 = 2.0