Python Online Compiler & Playground
HTML/CSS/JavaScript
HTML
CSS
Javascript
C++
C
PHP
Java
Python
Swift
C#
Ruby
Node.JS
Kotlin
jQuery
Go
R
TypeScript
Start Python Course
Register
square of a number without sqr function
+2
Author: Benjamin Alejandro Luna
Dark
Public
Save
PY
py
1
2
3
4
5
6
7
8
9
10
11
12
def
_sqr
(
x
):
result =
0
if
x <
0
:
x = x - x - x
for
i
in
range
(
x
):
result += x
return
result
n =
input
(
"enter a number "
)
y = _sqr
(
int
(
n
))
print
(
"the number is "
+ n
)
print
(
"and the square is "
+
str
(
y
))
Enter to Rename, Shift+Enter to Preview
OUTPUT