KEMBAR78
Assignment (Week 1) | PDF | Computer Programming
0% found this document useful (0 votes)
13 views8 pages

Assignment (Week 1)

The document contains a series of Python exercises focused on various programming concepts including temperature conversion, list manipulation, class creation, and dictionary usage. It demonstrates input handling, calculations, and the creation of objects, as well as basic data structures like tuples and lists. Each exercise provides code snippets that illustrate the implementation of these concepts.

Uploaded by

Nandar Lwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Assignment (Week 1)

The document contains a series of Python exercises focused on various programming concepts including temperature conversion, list manipulation, class creation, and dictionary usage. It demonstrates input handling, calculations, and the creation of objects, as well as basic data structures like tuples and lists. Each exercise provides code snippets that illustrate the implementation of these concepts.

Uploaded by

Nandar Lwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Week-1

Exercise

4.1

choice = input("Enter temperature unit you want to convert (1. Frenheit 2.Centigrade) : ")

choice = int(choice)

temperature = input("Enter temperature in {} ".format(choice_unit))

temperature = float(temperature)

if choice==1 :

calculation = (temperature-32)/1.8

print("Temperature in Centigrade is",calculation)

elif choice==2:

calculation = (temperature*1.8)+32

print("Temperature in Frenheit is",calculation)

4.2

count = int(input("Enter number count(s): "))

list1=[]

for x in range(count):

list1.append(input("Enter a number: "))

list1[x]=int(list1[x])

total = sum(list1)

print("Total of the numbers: ",total)

avg = total/count

print("Average of the numbers: ",avg)


4.3

person_info={'name':'Sue','Age':21,'Height':160,'Gender':'F'}

for k,value in person_info.items():

print(k,";",value)

(or)

class Person:

def __init__(self, name, age, height):

self.name = name

self.age = age

self.height = height

# Creating an instance

sue = Person('Sue', 16, 186)

# Accessing the information

print(f"Name: {sue.name}")

print(f"Age: {sue.age}")

print(f"Height: {sue.height} cm")

===================================

4.4

relationships = {
'David': {
'BossOf': ['Ken', 'Nick'],
'has': 'staff'
},
'Ken': {
'has': 'Department'
},
'Nick': {
'has': 'Department'
},
'Department': {
'has': 'staff'
}
}

# Accessing information
print(f"{list(relationships.items())[0][0]} is a boss of {relationships['David']['BossOf']}" )

# Prompting user for input


name = input("Enter your name: ")
age = input("Enter your age: ")
address = input("Enter your address: ")
gender = input("Enter your gender: ")

# Outputting the information


print("\nName:", name)
print("Age:", age)
print("Address:", address)
print("Gender:", gender)
z = [1,2,3]

print(z)

z.extend([4, 5, 6])

print(z)

z.append(0)

print(z)

z.pop(2)

print(z)

z.remove(2)

print(z)

z.index(1)

print(z)

for x in z:

print(x)

for i in range(len(z)):

print(z[i])

z.sort()

print(z)

z.sort(reverse = True)

print(z)

max_value = max(z)

print("Maximum value in the list:", max_value)

min_value = min(z)

print("Minimum value in the list:", min_value)


x = ["apple","banana"]

y = ["apple","banana"]

z=y

print(x is y)

print(y is z)

list = [1,2,3,4,5]

if 7 in list:

print ("3 is in the list")

else:

print ("is not found")

x = [1,2,3,4,5]

for i in x:

if i%2 == 0:

print(i)
turple=(1,'ko',2,'koko',3, 'KOKO')

turple1=('love u','miss u','care abt u')

turple2=('my love','mine','my world')

turple3=(turple,turple1)

turple4=(' koko_loveu ')*3

my_tuple = (10, 20, 30, 40, 20)

print(my_tuple.index(20))

print(my_tuple.index(20, 2))

print(my_tuple.count(20))

my_list_1 = list(my_tuple)

print(my_list_1)

age = int(input("Enter your age: "))

print("My age is", age)


print(type(age))

dict_1 = {"Name" : "SuSu", "age": 25, "address": "Yangon"}

print(dict_1["Name"])

for key, value in dict_1.items():

print(key , "=", value)


class Employee:

empCount = 0

name = None

salary = 0

def __init__(self, ename, esalary):

self.name = ename

self.salary = esalary

Employee.empCount+=1

def displayCount(self):

print("Total Employee",Employee.empCount)

def displayEmployee(self):

print("Name is: ", self.name, "Salary is: ", self.salary)

e1 = Employee("SuSu", 50000)

e2 = Employee("MgMg", 30000)

e3 = Employee("ThuThu", 40000)

e1.displayEmployee()

e2.displayEmployee()

e3.displayEmployee()

e1.displayCount()

You might also like