Skip to content

Commit 78e41fc

Browse files
Add files via upload
1 parent 3b291dc commit 78e41fc

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

assign3.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Sep 17 22:49:29 2019
4+
5+
@author: Ashay Fernandes
6+
"""
7+
8+
"""
9+
q> write a temperature converter python progra which is menu driven each such conversion logic
10+
should be defined in seperate functions.The program should call the respective function based on the users
11+
's requirement.the program should run as long as the user wishes so.provide an option to view the conversion
12+
stored as list of tuples with attributes from unit value to unit value sorted by the users choice"""
13+
14+
15+
lyst1=[]
16+
def celtokel():
17+
num=float(input("enter the Temperature in celsius"))
18+
val=num+273.15
19+
tup=["from-celsius:",num,"to-kelvin:",val]
20+
lyst1.append(tup)
21+
22+
def celtofah():
23+
num=float(input("enter the Temperature in celsius"))
24+
val=float((num * 9/5) + 32)
25+
tup=["from-celsius:",num,"to-fahrenheit:",val]
26+
lyst1.append(tup)
27+
28+
29+
def keltofah():
30+
num=float(input("enter the Temperature in kelvin"))
31+
val=float((num - 273.15) * 9/5 + 32)
32+
tup=["from-kelvin:",num,"to-fahrenheit:",val]
33+
lyst1.append(tup)
34+
35+
def tofrom():
36+
revlyst=[]
37+
for i in range(0,len(lyst1)):
38+
lyst2=[x for x in lyst1[i]]
39+
lyst2.reverse()
40+
j=lyst2[0]
41+
temp=lyst2[1]
42+
lyst2[0]=temp
43+
lyst2[1]=j
44+
j=lyst2[2]
45+
temp=lyst2[3]
46+
lyst2[2]=temp
47+
lyst2[3]=j
48+
revlyst.append(tuple(lyst2))
49+
print(revlyst)
50+
51+
while True:
52+
print('enter \n1:to convert from celsius to kelvin \n2:to convert from celsius to fahrenheit \n')
53+
print('3:convert from kelvin to fahrenheit\n4:to display values from -to-values\n5:to display values to-from\n6:exit')
54+
i=int(input())
55+
if i==1:
56+
celtokel()
57+
elif i==2:
58+
celtofah()
59+
elif i==3:
60+
keltofah()
61+
elif i==4:
62+
print(lyst1)
63+
elif i==5:
64+
tofrom()
65+
elif i==6:
66+
break;
67+
else:
68+
print('enter valid command')
69+
70+
71+

labwork3.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Sep 17 20:27:51 2019
4+
5+
@author: Ashay Fernandes
6+
"""
7+
"""
8+
<q> Write a python progran to do the following:
9+
a) Read a list of elemets. Create a new list having all the elements minus duplicate use functions.use
10+
one line comprehensions to create a new list of even numbers . create another list reversing the elements.
11+
"""
12+
lyst1=[]
13+
for i in range(0,5):
14+
lyst1.append(int(input("enter the list element(numbers)\n")));
15+
lyst2=[]
16+
def deldup(lyst):
17+
for i in lyst1:
18+
if i not in lyst2:
19+
lyst2.append(i)
20+
21+
deldup(lyst1)
22+
print(lyst2)
23+
24+
25+
#using list comprehension to generate a list of even numbers
26+
27+
lyst3=[x for x in lyst1 if x%2==0]
28+
29+
lyst4=[x for x in lyst1]
30+
lyst4.reverse()
31+
print(lyst4)
32+
33+
""" b> Write a python program to count the frequency of words in the given file
34+
"""
35+
36+
fhand=open('text.txt')
37+
x=fhand.read()
38+
lyst5=x.split()
39+
dictionary={}
40+
for i in lyst5:
41+
dictionary[i]=dictionary.get(i,0)+1
42+
43+
44+
for key,value in dictionary.items():
45+
print(key,value)
46+
47+
"""
48+
c> read a list of numbers.use a recursive function to find the maximum of 'n' numbers
49+
"""
50+
n= int(input("enter the size of list" ))
51+
lyst6=[]
52+
for i in range(0,n):
53+
lyst6.append(int(input('enter the number')))
54+
55+
def maximum(lyst,n):
56+
if n==1:
57+
return lyst[0]
58+
else:
59+
return max(lyst[n-1],maximum(lyst,n-1))
60+
maximum(lyst6,len(lyst6))
61+
62+
63+
64+
65+
66+
67+
68+

0 commit comments

Comments
 (0)