Python Revised

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Exp 1 A:

Algorithm: Step1: Initialize the program

Step2: Get the input from the user “Enter the radius of the Circle”

Step 3: Compute the Area circle using the formula = Pi * r ^2

Step 4: Print the output on the Screen Step 5: Stop the program

Exp 1B: Step 1: first initialize the program

Step 2: enter the values for a b c simultaneously.

Step 3: add three numbers a b c and assign it the keyword sum=a+b+c

Step 4: now to find average of three numbers divide by 2.total=sum/2

Step 5: print output on screen. Step 6: stop program


Exp 2 A: Step 1: Start.

Step 2: Declare a variable ‘a’.

Step 3: Store a string named “This is a sring” in a.

Step 4: Print a.

Step 5: Print “this is list”.

Step 6: Store [1, "a", "string", 1+2] in ‘a’.

Step 7: Print a.

Step 8: Add ‘5’ to list ‘a’.

Step 9: Print ‘a’.

Step 10: Remove the last value form list ‘a’.

Step 11: Print ‘a’.

Step 12: Print ‘a[1]’.

Step 13: Print “these are tuples”.

Step 14: Declare a Variable ‘tup’.

Step 15: Store (1, "a", "string", 1+2) in ‘tup’

Step 16: Print tup

Step 17: Print tup[1].


Step 18: END.

EXP2B:
EXP3A:

Step 1: Declare a variable ‘height’.

Step 2: Read the input and store in ‘height’.

Step 3: Declare a variable ‘weight’.

Step 4: Read the input and store in ‘weight’.


Step 5: Calculate weight / (height * height).

EXP 3B:

Step1: Initialize the program.

Step2: Get the input from the user "Input lengths of the triangle sides: "

Step 3: Check if X = Y and Y = Z. If found to be true, print “EquilateralTriangle”.

Step 4: If it is not an Equilateral triangle, then check if X = Y or X = Z or Y = Z. If found tobe true, print “Isosceles Triangle”.
Step 5: If none of the above steps are satisfied, then print “Scalene Triangle”.

Step 6: Print the output on the Screen.

Step 7: Stop the program.


EXP 4 a:

Step1: Initialize the program.

Step2: Get the input from the user asfor loop which ranges from the lower range to the upperrange.

Step 3: Compute the numbers which are divisible by 7 and multiple of 5.

Step 4: Print the output the numbers on the screen.

Step 5: Stop the program


EXP 4B:

Step1: Initialize the program.

Step2: Use for loop with range 11.

Step 3: Use conditional statement if x=3,6,9.

Step 4: For each iteration it checks whether the i=3,6,9 if it is not the directly print x and itends up if i=3,6,9 it continue
to for loop and again it iterate.

Step 5: Print the output the numbers on the screen.

Step 6: Stop the program

EXP 5 A:

Step 1: Start the program.

Step 2: Import math as math module.

Step 3: Use s=(a+b+c)/2 as a semi perimeter.


Step 4: Use formula math.sqrt((s*(s-a)(s-b)(s-c)) to find area of triangle.

Step 5: Print specified output.

Step 6: Stop the program

EXP 5 B:

Step 1: Start the program.

Step 2: Create a random module as import random.

Step 3: Use for i in range(50) for 50 random numbers.

Step 4: Print the numbers between the range (1,100) by using random.randint() function.

Step 5: Stop the program.

EXP 6b:

Step 1: Start the program.

Step 2: Create a list of strings.

Step 3: Add empty list str1 =[].

Step 4: for strs in string: used to iterate the each word in a list.

Step 5: if strs not in str1:

str1.append(strs) it appends to the empty list.

Step 6: Print the specified output.

Step 7: Stop the program.


6 something idk:

Step 1: start the program.

Step 2: define function with def binary_search_iterative(array, element):

Step 3: add mid , start , end , step to search an element.

Step 4: while (start <= end):

Step 5: divide the array into two parts to search an element in arraystep = step+1 mid = (start + end) // 2

Step 6: if element is found in mid return midif element == array[mid]: return mid

Step 7: if element is less than mid value it searches left sideif element < array[mid]: end = mid – 1

Step 8: else if element is greater than mid it searches right sideelse: start = mid + 1

Step 9: give the array and element to search of list it takes step 1 to 8.

Step 10: print the position of element.

Step 11: print specified output.

Step 12: stop the program.


Also 6:

Step 1: start the program

Step 2: create a dictionary with keys and values.

employee={"kamani":20000,"praveena":30000,"Sri":45000,"madhu":31200}

Step 3: ask user to input the employee name.

Step 4: ask user to enter extra hours that the employee worked

Step 5: calculate gross salary by adding extra hours gross=overtime*250

Step 6: use for loop to search the employee name in the dictonaryfor i in employee:

Step 7: if name found in dictionary the gross salary for employee will be addedif name==i: grossalary=employee[name]
+gross

Step 8: print the specified output


Step 9: stop the program

6 G:

Step 1: start the program.

Step 2: create a dictionary words={"Praveena":1,"Kamani":1,"class":12}.

Step 3: word=words.values() to store values in dictonary.

Step 4: d = dict() empty dictionary.

Step 5: for c in word:

Step 6: if c not in d: d[c] = 1 if c is not in d c value becomes 1

Step 7: else: d[c] = d[c] + 1 if it is in values it counts 1

Step 8: print the specified output.

Step 9: stop the program

7A:

Step 1: Start the program.

Step 2: Take a number as input.

Step 3: Use if loop and check whether number is greater than one or not.
Step 4: Use if loop take range above 2 and if (number % i) is equal to zero then the numberis not prime so print(number,
"is not a prime number")

Step 5: if (number % i) is not equal to zero then the number is prime soprint(number, "is a prime number")

Step 6: Print specified output.

Step 7: Stop the program.

7B:

Step 1: start the program

Step 2: use def function def the(random): return random -> it takes random list to function

Step 3: random=[15,24] creates a random list

Step 4: sort in ascending order random.sort()

Step 5: print the specified output

Step 6: stop the program

8B:

Step 1: start the program.

Step 2: from time import process_time.

Step 3: start_time=process_time()

Step 4: number=int(input("Enter a number"))//user to input a numberfor i in


range(number)://for loop

print(i, end="")

Step 5: stop_time=process_time()

Step 6: total_time= stop_time – start_time

Step 7: print the specified output.

Step 8: stop the program.

10A:

Step 1: start the program.

Step 2:outfile = open("/content/drive/MyDrive/Colab Notebooks/data.txt", "r")filein=outfile.read()

Step 3: counter = 0

Step 4: coList = filein.split("\n")

Step 5: for i in coList: if i: counter += 1

Step 6: print the specified output.

Step 7: stop the program


11:

Step 1: start the program.

Step 2: class InvalidAgeError(Exception):

Step 3: def _init_(self, arg): self.msg = arg

Step 4: def vote_eligibility(age):

Step 5: conditional statements with if and else

Step 6: try: vote_eligibility(22) vote_eligibility(14) except InvalidAgeError as error: print(error)

Step 7: print specified output.

Step 8: stop the program

12:

Step 1: start the program.

Step 2: create a class rectangleclass Rectangle:

Step 3: define init() function with object and propertiesdef _init_(self, height, width): self.height = height self.width =
width

Step 4: define reactangle_area def rectangle_area(self): return self.height*self.width //compute the formula and brings
area
Step 5: define a rectangle_perimeterdef rectangle_peri(self): return 2*self.height+self.width. // compute the formula
and bring perimeter

Step 6: give the values of height and width for two for rectangles to compute area and perimeter Rectangle_1=
Rectangle(24, 12) Rectangle_2 = Rectangle(12,25)

Step 7: print the two rectangle area and perimeter

Step 8: print the specified output.

Step 9: stop the program.

13:

Step 1: start the program

Step 2: create parent class or base classclass Mobile:

Step 3: add the init() function to create a new objectdef _init_(self, model,year):

Step 4: self.model=model //creates objects with propertiesself.year=year

Step 5: use function to display and retun properties of object.def display(self): return(self.model, self.year)

Step 6: create a child class which will extend the properties of parent classclass price(Mobile): def _init_(self,
model,year,price):

Step 7: use super() function to inherit the properties of parent to child classsuper()._init_(model, year) self.price=price
Step 8: define a function used to return the properties of child class with parentdef pricing(self):
return(self.display(),self.price)

Step 9: create user defined input m1=price("iphone12",2020,83000)

Step 10: print the specified output.

Step 11: stop the program

You might also like