-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasiccodes.py
More file actions
58 lines (30 loc) · 1.03 KB
/
basiccodes.py
File metadata and controls
58 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# function find string greater than length k
def string_k(k, str):
string = []
text = str.split(" ")
for x in text:
if len(x) > k:
string.append(x)
return string
k = int(input("enter a number: "))
str = input("enter a string: ")
print(string_k(k, str))
radius = int(input("enter the radius of a circle: "))
pi = 3.14
# formulae to find area of circle
area = pi*(radius*radius)
print (f"Area of circle is {area}")
############################## sum of squares of first N natural numbers #######################################################
n = int(input("enter a number: "))
sum=0
for i in range (n+1):
i = i**2
sum = sum+i
print(f"sum of squares of {n} natural numbers is {sum}")
############################## sum of cubes of first N natural numbers #######################################################
n = int(input("enter a number: "))
sum=0
for i in range (n+1):
i = i**3
sum = sum+i
print(f"sum of cubes of first {n} natural numbers is {sum}")