Sunday, 16 January 2022

Notes: 16th Jan

 3:16 PM 16-Jan-22


files:

storing data: 

Creating and storing data into the file:

with open("greet.txt", "w") as f:

( file can be rewritten if data already exists in the file )


Reading from the file:

with open("greet.txt", "r") as f:

text_of_file = f.read()


Appending a file to already existing file:

with open("greet.txt", "a") as f:

f.write("\nHave a nice day!")


with open("greet.txt") as f:

message = f.read()

print(message)





Friday, 14 January 2022

Programmes: 12-14th Jan

 #list of items and thier deductions#


def present(salary):

    total = expenditures()

    remaining = salary - total

    print(f'your remaining salary is {remaining}')



def expenditures():

    type = input('enter the type of deduction')

    cutting = input('what is the amount')

    list1 = []

    list2 = []

    while type != '' and cutting != '':

        list1.append(type)

        list2.append(cutting)


        type = input('enter the type of deduction')

        cutting = input('what is the amount')

    deductions = {}

    for i in range(0,len(list1)):

     deductions[list1[i]] = list2[i]



    total = sum(map(int, list2))

    for item,amount in deductions.items():

        print('deduction for an item {} is {}'.format(item,amount))

    return total



present(50000)


#factorial of number#

fact = int(input('enter the item no'))

x = []

x.append(fact)


i = 0

j = 1

k = fact

def single():

      print('factorial of 1 is 1')

if fact == 1:

      single()


else:

    while k != 1:

        p = x[i] * (k - j)

        x.append(p)

        i = i + 1

        k = k - 1

    print(p)


Wednesday, 12 January 2022

Programmes Part 1:


#list of things to be displayed whatever which are entered#
list = input('enter list of items:')
total = [list]

while list != '':



    list = input('enter list of items:')
    total.append(list)









else:
    print('list of things to do for today:')
    for i, list in enumerate(total, start=1):
        print(i,list)

#list of things to be displayed which are in dictionary#
people = {'john': 'he plays guitar', 'Sachin': 'master blaster'}

people['Karuna'] = 'An Artist'

people['john'] = 'he plays drums and guitar too'
for person, qualities in people.items():
    print('quality for {0} is {1}. '.format(person, qualities))


# To get maximum value from the dictionary #
Grades = {'Nataraj': 50, 'Manishi': 60, 'Ambootu': 20}

print(max(Grades.items()))



class student():
    def getstudentdetails(self):
        self.firstname = input('enter student first name')
        self.lastname = str(input('enter you student last name'))
        self.age = input('enter your age')
        self.Score = int(input('enter your test score'))
        self.Scholarship = input('Please enter Yes or NO')


s1 = student()
s1.getstudentdetails()
x = s1.Score
if x >= 60:
    print(f'{s1.lastname} Student is eligible for admission')
else:
    print(f'{s1.lastname} Student is not eligible for admission')
if x >= 80:
    print(f'{s1.lastname} Student is eligible for scholarship')



num = int(input('enter a number'))
if(num % 2) == 0:
    print(f"{num} is Even")
else:
    print(f"{num} is odd")






name continent area population gdp
Afghanistan Asia 652230 25500100 20343000000
Albania Europe 28748 2831741 12960000000
Algeria Africa 2381741 37100000 188681000000
Andorra Europe 468 78115 3712000000
Angola Africa 1246700 20609294 100990000000
...


In this tutorial you will use the SELECT command on the table world:


Show the name and population for France, Germany, Italy





item =input('enter item:')
cost = input('enter cost of the item')

items = []
Price = []


while item != '' and cost != '':
    items.append(item)
    Price.append(cost)
    item = (input('enter item:'))
    cost = input('enter cost of the item')



ration = {}


for i in range(0,len(items)):
  ration[items[i]] = Price[i]




print(ration)



Notes: Dec 16th to 13th Jan

16/dec/2021

....................................................................

exception handling

Sorted and ranges


{}.format(defined variable): this is used when you list the number of items in index in a particular format.You can only call them using this syntax.


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

20th-21st Dec 2021

---------------------------

While < condition >

------statement


to display the no of items in sequential order which are stored in the index

for i, list in enumerate(total, start=1):

        print(i,list)

where total is the array and i is the serial no


adding items to the index

total.append(list)

where total is the index which stores item values and list is the item which you're going to enter into the index


creating dictionaries:

dictionary = { key1:value1, key2:value2.............. }


inserting key and values in the dictionary

dictionary[key3] = value 1


deleting dictionary items from the list:

people.pop(k)

k= Variable where dictionary items are saved


to find out max or minimum from dictionary:

min(Grades.items())

Grades is the dictionary we created and items are the values we entered in the dictionary.


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

5:12 PM 27-Dec-21

del is used to remove items from list,below is the syntax:

del electronics[0]


Sort:

Inorder to get the list in sequence we'll use this sort function,original sequence will be affected after using this function:

electronics.sort()


reverse():

sequence can be reversed using this function:

electronics.reverse()


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

1:50 PM 28-Dec-21


from pprint import pprint:

pprint is the python builtin module which is used to print out well formatted datatypes in python


string.ascii_lowercase: returns list of characters from A to Z


      





Notes: 16th Jan