0
SyntaxError - but why??
import math a = float(input() if type(number) == float: x = a print("sin "+x+"° = "math.sin(x)) elif type(number) == int: x = int(a) print("sin "+x+"° = "math.sin(x))
5 ответов
+ 2
JUMP_LINK__&&__Python__&&__JUMP_LINK Learner
Since there is : a = float(input()),
why do you need if and elif block at all ?
The same code can be written in 3 lines:
import math
a = float(input())
print(f"sin{a} = {math.sin(a)}")
You can add exception in second line for string input ..
Correct me if im wrong 😊
+ 2
Hi Sacar!
Of course, you're correct.
But I was trying to help him in his style specifically, concatenation. The way you mentioned is also used for concatenation.
+ 2
JUMP_LINK__&&__Python__&&__JUMP_LINK Learner gotcha, bro !
+ 1
Hi Ferdous!
You let some small mistakes here. One thing is that you have to convert integers to string in concatenation when you're using "+" as concatenation operator but it cannot be used between a string and float. For that, you can use comma instead.
Here it is your working code.
import math
a = float(input())
if type(a) == float:
x = a
print("sin ",x,"° = ",math.sin(x))
elif type(a) == int:
x = int(a)
print("sin ",x,"° = ",math.sin(x))