Skip to content

Instantly share code, notes, and snippets.

@samy1223
samy1223 / S23Q02
Created December 27, 2018 11:21
Create a class called Student that has attributes called - name, age and marks. - Read a file that contains list of students with their individual information given in one line each. - Store this information is separate Student objects. - Use the objects created above to - Print the complete information about the students with the top 3 highest …
class student:
def __init__(self, name, age, marks):
self.name1 = name
self.age1 = age
self.marks1 = marks
def read_file(FH):
file1 = FH.read()
file2 = file1.split()
return file2
@samy1223
samy1223 / S23Q01
Created December 27, 2018 09:52
Create a class called Car. - It should have a method to - reset its odometer reading, - set its mileage and - set its fuel tank capacity. Create an object of this Car class and perform the following steps. Prompt the user to set the mileage and fuel tank capacity of the car. Then ask the user to enter the odometer reading at the end his travel. …
class car:
def __init__(self,odometer,milage,capacity):
self.odometer1 = odometer
self.milage1 = milage
self.capacity1 = capacity
def milageNumber():
mil = input("Enter the milage: ")
return mil
@samy1223
samy1223 / S18Q02
Created December 26, 2018 06:29
The lap speeds recorded for Michael Schumacher, Montoya Juan-Pablo and Barrichello Rubens in a F1 race are ( 258.626, 255.931, 258.998, 255.195 ), (258.680, 257.925, 259.828, 257.422) and (258.405, 256.700, 260.395) respectively - Find the fastest lap for each driver - Find the average speed for each driver - Which driver has recorded the fastes…
from statistics import mean
def Average(lst):
return mean(lst)
dict = {}
tempkey = []
tempvalue = []
dictList = []
@samy1223
samy1223 / S18Q01
Created December 26, 2018 03:39
Shell Environment variables are shown below. - Use “keys()” and “items()” methods to print the names of all the environment variables - Which environment variables has the longest name ? - Print the names of all the environment variables in a sorted order - Print the names and values of environment variables in the following format : - NAME = va…
shelltext = dict()
key1 = shelltext.keys()
print (key1)
key1.sorted()
print (key1)
@samy1223
samy1223 / S17Q03
Created December 21, 2018 17:36
Write a Python program that takes a file name as its argument. This file contains names of people and their corresponding contact numbers. - Prompt the user to enter a few characters to search for. - Print all the names that contain this sequence of characters in the ascending order of their names
def read_line(FH):
text_file = FH.read()
mytext_file = text_file.split()
return mytext_file
def search_word():
name1 = input("Enter the name to search: ")
return name1
@samy1223
samy1223 / S17Q01
Created December 20, 2018 11:33
Write a Python program that takes a file name as its argument. This program should count the occurrences of all the words in a file. - It should then print the top 10 most repeated words in the descending order of their count. - Print a separate list of all the words that are not repeated in that file.
def read_line(FH):
text_file = FH.read()
all_files = text_file.split()
return all_files
def main():
@samy1223
samy1223 / S16Q02
Created December 20, 2018 08:47
Write a Python program that prompts the user for a file. This file contains names of people and their ages. Read the file, and print the list with the oldest person’s name listed first. A sample file [ AGES.TXT ] is shown above :
age = {'sam':45,'ram':64,'kiran':65}
a1_sorted_keys = sorted(age, key=age.get, reverse=True)
for r in a1_sorted_keys:
print (r, age[r])
@samy1223
samy1223 / S16Q01
Created December 20, 2018 08:37
Write a Python program that takes a file name as its argument. This file contains names of people and their corresponding contact numbers. Read the file, and print the list in the ascending order of their names. A sample file [ CONTACT_LIST.TXT ] is shown below :
from collections import OrderedDict
contacts = {'sam':1222,'ram':53232,'samy':64343}
OrderedDict(sorted(contacts.items(), key=lambda t: t[0]))
print (contacts)
@samy1223
samy1223 / S14Q03
Created December 20, 2018 06:02
Ask the user to enter any 10 numbers as input. Randomly pick any 5 numbers from this list but print them in the same order as given by the user.
import random
def numbers():
list=[]
for i in range(1,11):
rand_number = input("Enter the number: ")
list.append(rand_number)
return list
def main():
@samy1223
samy1223 / S14Q02
Created December 20, 2018 05:27
Create a text file called “students.txt”. Each line should be of the form “student_name : student_marks” - Write a Python program to read the contents from this file. - Print the names and marks of all students who have scored more than 90% marks, in ascending order of their marks.
def namemark():
name, mark = input("Enter name and mark: ").split() # taking two inputs at a time
if (mark > 90):
return name,mark
def main():
myfile = open("numberfile.txt","a")
number_entered = namemark()