Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cda0021

Browse files
Practice Question
1 parent e986954 commit cda0021

File tree

93 files changed

+1272
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1272
-0
lines changed

‎10_alphabets.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# printing first 10 aplhabets in list form
2+
x = []
3+
for i in range(97,107): # alphabets can be printed using ascii numbers
4+
i = chr(i)
5+
x.append(i)
6+
print(x)

‎abbrevations.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# example The Jungle Book should be displaye as TJB
2+
def abs(str_1):
3+
str_2 = str_1.split(" ") # .split(" ") seprates the words at blank
4+
for i in str_2:
5+
print(i[0].upper(),end="")
6+
7+
8+
string_1 =input("enter the string: ")
9+
abs(string_1)

‎add and sub fraction.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# making a class to add and subtract a fraction
2+
class Fraction:
3+
def __init__(self, a, b, c, d):
4+
self._a = a
5+
self._b = b
6+
self._c = c
7+
self._d = d
8+
9+
def sum(self):
10+
add = (self._a / self._b) + (self._c / self._d)
11+
print("The sum of numbers is: ", add)
12+
13+
def diff(self):
14+
sub = (self._a / self._b) - (self._c / self._d)
15+
print("the difference of the numbers is: ", sub)
16+
17+
18+
w = float(input("enter the numerator of first number"))
19+
x = float(input("enter the denominator of first number"))
20+
y = float(input("enter the numerator of second number"))
21+
z = float(input("enter the denominator of second number"))
22+
result = Fraction(w, x, y, z)
23+
result.sum()
24+
result.diff()

‎add_ing_at_end.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# adding ing at the end if character is longer then 3, if ing already there then add ly
2+
def string(str_1):
3+
if len(str_1)<3: # len shows the length of the string
4+
return str_1
5+
elif len(str_1)>3:
6+
if str_1[len(str_1)-3:] != "ing":
7+
return str_1 + "ing"
8+
elif str_1[len(str_1)-3:] == "ing":
9+
return str_1 + "ly"
10+
11+
12+
line = input("enter the string: ")
13+
print(string(line))

‎age.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# enter current year and your birthe year and code will display your age
2+
x = int(input("enter the current date, month and year resp \n"))
3+
y = int(input())
4+
z = int(input())
5+
a = int(input("enter the birth date, month and year resp \n"))
6+
b = int(input())
7+
c = int(input())
8+
age = z - c # current year minus birth year
9+
z = str(z)
10+
c = str(c)
11+
print("Date of birth is",str(a) +"/",str(b)+"/",str(c[2]),str(c[3]))
12+
print("Current date is",str(x) +"/",str(y)+"/",str(z[2]),str(z[3]))
13+
print("Age of person is",age)

‎alphabetical.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# sorting the elements of a list
2+
x = []
3+
y = int(input("enter the number of elements: "))
4+
for i in range(y):
5+
z = str(input("enter any element: "))
6+
x.append(z)
7+
x.sort()
8+
print("The sorted order of the list is: ", x)

‎alphbet_or_digit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# determining whether the character entered is a digit or alphabet
2+
x = input("enter any character")
3+
if x.isdigit(): # checking for digit
4+
print("enter input is digit")
5+
elif x.isalpha(): # checking for alphabet
6+
print("input is alphabet")
7+
elif x.isspace(): # checking for space
8+
print("white space")
9+
else:
10+
print("wrong input")

‎area.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Finding the area of a triangle using class
2+
import math
3+
4+
5+
class Triangle:
6+
def __init__(self, side1, side2, side3):
7+
self._side1 = side1
8+
self._side2 = side2
9+
self._side3 = side3
10+
self._semi_perimeter = 0
11+
12+
def semi(self):
13+
self._semi_perimeter = (self._side1 + self._side2 + self._side3)/2
14+
area = math.sqrt((self._semi_perimeter)*(self._semi_perimeter-self._side1)
15+
*(self._semi_perimeter-self._side2)*(self._semi_perimeter-self._side3))
16+
print("The area of the given triangle is", area)
17+
18+
19+
a = int(input("enter the first side: "))
20+
b = int(input("enter the second side: "))
21+
c = int(input("enter the third side: "))
22+
AREA = Triangle(a, b, c)
23+
AREA.semi()
24+

‎area_triangle.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# program to find the area of a triangle
2+
import math # importing math module
3+
def area(x,y,z):
4+
s = (x + y + z)/2
5+
ar = math.sqrt(s*(s-x)*(s-y)*(s-z)) # this is the formula to find area
6+
return ar
7+
8+
9+
a = int(input("Enter a side: "))
10+
b = int(input("Enter a side: "))
11+
c = int(input("Enter a side: "))
12+
print(area(a,b,c))

‎assertion error.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# The numberes should be entered as asked unless display to correct mistake
2+
x = int(input("enter the larger number: "))
3+
y = int(input("enter the smaller number: "))
4+
try:
5+
if x > y:
6+
print("you entered the right numbers")
7+
else:
8+
raise AssertionError
9+
except AssertionError:
10+
print("Sorry you didn't entered the numbers correctly")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /