Urhsndhrvanakwhzbxhdak
Urhsndhrvanakwhzbxhdak
A Basic Python program that reads student details, calculates the total marks, and
percentage, and then displays the results:
print("Enter the name of the Student")
name=input()
print("Enter the USN of the Student")
usn=input()
print("Enter the subject1 marks")
sub1=input()
print("Enter the subject2 marks")
sub2=input()
print("Enter the subject3 marks")
sub3=input()
total=int(sub1)+int(sub2)+int(sub3)
avg=int(total)/3.0
print("****************************************")
print("\t Student Details")
print("****************************************")
print("\t Student Name: ",name)
print("\t Student USN: ",usn)
print("\t Subject1 Marks: ",sub1)
print("\t Subject2 Marks: ",sub2)
print("\t Subject3 Marks: ",sub3)
print("*****************************************")
print("\t Total Marks: ",total)
print("Average of the marks: ",float(avg))
Alternate Program
# Read student details
name = input("Enter the student's name: ")
usn = input("Enter the student's USN: ")
# Calculate age
age = current_year - year_of_birth
# Print a separator
print("####################")
Alternate Program
import numpy as np
# Prompt the user to enter N elements and add them to the list
print(f"Enter {n} elements to the list. \"Enter them one by
one.\"")
for i in range(n):
ele = input()
lst.append(int(ele))
4 Read a multi-digit number (as chars) from the console. Develop a program to print
the frequency of each digit with suitable message.
print("Enter a mutidigit number:")
num=input()
dict={}
for x in num:
if x in dict:
dict[x]+=1
else:
dict[x]=1
print(str(dict))
5 Develop a program to print 10 most frequently appearing words in a text file. [Hint:
Use dictionary
import operator # Import the 'operator' module
6 Develop a program to sort the contents of a text file and write the sorted contents
into a separate text file. [Hint: Use string methods strip(), len(), list methods sort(),
append(), and file methods open(), readlines(), and write()].
# Prompt the user to enter a file name
print("Enter the file name:")
fname = input()
if os.path.exists('backup-folder.zip'):
print("The path the folder is zipped:::")
print(archived)
else:
print("ZIP file not created")
8 Write a function named DivExp which takes TWO parameters a, b and returns a
value c (c=a/b). Write suitable assertion for a>0 in function DivExp and raise an
exception for when b=0. Develop a suitable program which reads two values from
the console and calls a function DivExp.
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
def DivExp(x, y):
try:
z=x/y
print("Quotient:",z)
except ZeroDivisionError:
print("Division by Zero!")
DivExp(a, b)
9 Define a function which takes TWO objects representing complex numbers and
returns new complex number with a addition of two complex numbers. Define a
suitable class ‘Complex’ to represent the complex number. Develop a program to
read N (N >=2) complex numbers and to compute the addition of N complex
numbers.
class Complex ():
def initComplex(self):
self.realPart = int(input("Enter the Real Part: "))
self.imgPart = int(input("Enter the Imaginary Part: "))
def display(self):
print(self.realPart,"+",self.imgPart,"i", sep="")
c1 = Complex()
c2 = Complex()
c3 = Complex()
10 Develop a program that uses class Student which prompts the user to enter marks in
three subjects and calculates total marks, percentage and displays the score card
details. [Hint: Use list to store the marks in three subjects and total marks. Use init
() method to initialize name, USN and the lists to store marks and total, Use
getMarks() method to read marks into the list, and display() method to display the
score card details
class StudentData:
def __init__(self):
self.Total = 0.00
self.Average = 0.00
self.Percentage = 0.00
self.Marks = []
self.MaxMarks = 0.00
def main(self):
print("Enter the marks of five subjects::")
for i in range(5):
self.Marks.append( float (input ()))
if c == len (self.Marks):
return 'Passed'
else:
return 'Failed'
StudentData.main()