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

25th Aug 2021, 11:06 AM
FꫀâČ…áƒ«á„†ÍŸá„™á„‰áŻœ
FꫀâČ…áƒ«á„†ÍŸá„™á„‰áŻœ - avatar
4 Answers
+ 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 😊
25th Aug 2021, 12:52 PM
Sacar
Sacar - avatar
+ 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.
25th Aug 2021, 2:52 PM
Python Learner
Python Learner - avatar
25th Aug 2021, 3:07 PM
Sacar
Sacar - avatar
+ 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))
25th Aug 2021, 11:14 AM
Python Learner
Python Learner - avatar