+ 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))

26th Aug 2019, 4:21 PM
Onimisi
Onimisi - avatar
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
26th Aug 2019, 5:15 PM
Lothar
Lothar - avatar
+ 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))
26th Aug 2019, 4:27 PM
Airree
Airree - avatar
+ 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
26th Aug 2019, 5:08 PM
Fredrik Kaspersen