Skip to content

Commit 8e3f54a

Browse files
committed
Update
1 parent 0aa643f commit 8e3f54a

File tree

3 files changed

+109
-42
lines changed

3 files changed

+109
-42
lines changed

.idea/workspace.xml

Lines changed: 67 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

7_Functions/12_IntroToFunctions.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,28 @@
55
To call a function, use the function name followed by parenthesis.
66
'''
77

8-
def random():
9-
pass
8+
# Let us write a function to calculate area_of_circle.
9+
10+
pi = 3.14159 # we assign a value to variable "pi"
11+
12+
13+
def area_of_circle(r): # create a function named area_of_circle and parameter "r"
14+
return pi * r * r # the formula to calculate area_of_ circle
15+
16+
17+
print(area_of_circle(5)) # prints area of circle with radius 5. Change '5' to '6' and run.
18+
19+
x = int(input("Enter radius(r): ")) # we can even ask for user input and calculate area
20+
print("Area of circle from user input: ", area_of_circle(x))
21+
22+
23+
# Calculate volume of cone from user inputs
24+
# we will use pi which has been declared above
25+
26+
def volume_of_cone(r, h):
27+
return (1 / 3) * pi * (r * r) * (h) # return means to give back the value obtained
28+
29+
30+
r = int(input("Enter radius(r): "))
31+
h = int(input("Enter height(h): "))
32+
print("Volume of cone from user input is: ", volume_of_cone(r, h))

8_MiniPrograms/14_Palindrome.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'''
2+
Let us write a program to check if a given string is Palindrome or Not.
3+
A palindrome is a string that reads the same forward or reversed.
4+
Eg: 'abba' is Palindrome, '12321' is palindrome, 'abda' is not a palindrome.
5+
'''
6+
7+
8+
def palindrome(pal):
9+
for i in range(len(pal) // 2): # to find the central value and iterate till there
10+
if pal[i] != pal[len(pal) - i - 1]: # checks if last element is equal to first, 2nd last equal to 2nd and so on
11+
return ("'{:s}' is not a Palindrome".format(pal))
12+
13+
return ("'{:s}' is Palindrome".format(pal))
14+
15+
16+
pal = str(input("Enter a string: "))
17+
print(palindrome(pal))

0 commit comments

Comments
 (0)