+ 1

Whats wrong with this simple pythone code?

1 col=input(); 2 per=col; 3 per=per/100; 4 print(per); This simple code gives error and point 3 string Whats wrong with that?(sorry for bad English)

14th May 2020, 11:32 PM
DankAvHi
DankAvHi - avatar
5 Respuestas
+ 5
input defaults as string and you get a TypeError when you want to divide a string by an int data type at line 3 to avoid this you need to convert the string into an int by doing this: col=int(input())
14th May 2020, 11:35 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 4
Avinesh they can be used as newliners so you can write multiple statements in one line but that just makes the code much uglier. they are literally ignored if you add them just as an ending to a statement
14th May 2020, 11:44 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 2
I did not know that semicolons could be used in Python to terminate a statement.
14th May 2020, 11:40 PM
Avinesh
Avinesh - avatar
+ 2
Sebastian Pacurar thanks for sharing this, I am new to Python and have missed these small details.
14th May 2020, 11:47 PM
Avinesh
Avinesh - avatar
0
Thanks
14th May 2020, 11:36 PM
DankAvHi
DankAvHi - avatar