From 6a6220a008b412fec84047c9492ed148fde5be39 Mon Sep 17 00:00:00 2001 From: khannariya9 <42000538+khannariya9@users.noreply.github.com> Date: Fri, 17 Apr 2020 12:50:02 +0530 Subject: [PATCH 1/3] Add files via upload --- Riya Khanna/Linux(4).txt | 8 ++++ Riya Khanna/Python(4).txt | 86 +++++++++++++++++++++++++++++++++++++++ Riya Khanna/python(3).txt | 38 +++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 Riya Khanna/Linux(4).txt create mode 100644 Riya Khanna/Python(4).txt create mode 100644 Riya Khanna/python(3).txt diff --git a/Riya Khanna/Linux(4).txt b/Riya Khanna/Linux(4).txt new file mode 100644 index 0000000..8f6cfd0 --- /dev/null +++ b/Riya Khanna/Linux(4).txt @@ -0,0 +1,8 @@ +1.Meaning of d in yum install command. +Ans. The d means “Download only” which will download to /var/cache/yum/arch/prod/repo/packages/, but won’t install them. + +2.Difference between rpm -e and yum remove. +Ans. YUM remove can remove rpm packages, but it will only remove the rpm package requested and not anything that package depends on. +This is because if you follow the dependencies on removal, you'll end up removing something like libc, or the kernel, which you'd probably rather keep. +While rpm -e command, reviews the RPM database to find every file listed as being part of the package, and if they do not belong to another package, deletes them. +It also checks the RPM database to make sure that no other packages depend on the package being erased and it executes a pre/post-uninstall script (if one exists). diff --git a/Riya Khanna/Python(4).txt b/Riya Khanna/Python(4).txt new file mode 100644 index 0000000..a3b5a70 --- /dev/null +++ b/Riya Khanna/Python(4).txt @@ -0,0 +1,86 @@ +Q1. Write a program to print new list which contains all the first character of the strings present in a list. +Ans1. +list=["GOA","RAJASTHAN","KARNATAKA","GUJRAT","MANIPUR","MADHYA PRADESH"] +new_list=[] +for i in list: + new_list.append(i[0][0]) +print(new_list) + +Q2. Write a program to replace each string with an integer value in a given list of strings. +The replaced integer value should be the sum of ASCII values of each character of type corresponding string. +Ans2. +l=['GAnga','Tapti','Kaveri','Yamuna','Narmada'] +c=[] +for i in l: + j=0 + sum=0 + for j in i: + sum=sum + ord(j) + c.append(sum) +print(c) + +Q3. Run any Program at 9:00m. Date: 14th April 2020. +Ans3. +import datetime +import time +task_date = datetime.datetime(2020, 4, 14, 9, 0, 0) +while datetime.datetime.now() < task_date: + time.sleep(1) + +print("Hello! Its 14th April") + + +Q4.Given a tuple: +tuple = ('a','l','g','o','r','i','t','h','m') +1. Using the concept of slicing, print the whole tuple +2. delete the element at the 3rd Index, print the tuple. +Ans4. 1) print(tuple[:]) +2.) +tuple=tuple[0:3]+tuple[4:] +print(tuple) + +Q5. Take a list REGex=[1,2,3,4,5,6,7,8,9,0,77,44,15,33,65,89,12] +- print only those numbers greater than 20 +- then print those numbers those are less then 10 or equal to 10 +- store these above two list in two different list. + +REGex=[1,2,3,4,5,6,7,8,9,0,77,44,15,33,65,89,12] +lst1=[] +lst2=[] +for i in REGex: + if i >20: + lst1.append(i) + + if i <=10: + lst2.append(i) + + +print(lst1) +print(lst2) + +Q6. Execute standard LINUX Commands using Python Programming. +Ans6. +import os +cmd = 'wc -l my_text_file.txt > new.txt' +os.system(cmd) + +Q7.Revise *args and **kwargs Concepts. +*args passes variable number of non-keyworded arguments list and on which operation of the list can be performed. +**kwargs passes variable number of keyword arguments dictionary to function on which operation of a dictionary can be performed. +1) *args +def sum(*n): + sum = 0 + for i in n: + sum = sum + i + + print("Sum:",sum) + +sum(3,5) +sum(4,5,6,7) +sum(1,2,3,5,6) + +2) **kwargs +def print_kwargs(**kwargs): + print(kwargs) + +print_kwargs(kwargs_1="riya", kwargs_2='khanna', kwargs_3=True) \ No newline at end of file diff --git a/Riya Khanna/python(3).txt b/Riya Khanna/python(3).txt new file mode 100644 index 0000000..1fe07f7 --- /dev/null +++ b/Riya Khanna/python(3).txt @@ -0,0 +1,38 @@ +Q1. Find the Armstrong number between the numbers input by the user. +Ans1. +import math +a=int(input("Enter the lower limit:")) +b=int(input("Enter the upper limit:")) +lst=[] +for i in range(a,b+1): + x=i + n=0 + while x!=0: + x=x//10 + n=n+1 + + p_sum=0 + x=i + while x!=0: + digit=x%10 + p_sum=p_sum+ math.pow(digit,n) + x=x//10 + + if p_sum==i: + lst.append(i) +print(lst) + +Q2. Remove the special characters except spaces from the string " hello this world @2020!!!" +Ans2. +import re +string = "hello this world @2020!!!" +string = re.sub('[^a-zA-Z.\d\s]', '', string) +print(string) + +Q3. You have a list of words=['Apple','banana','cat','REGEX','apple']. Sort the words in alphabetical order. +Ans3. +words=['Apple','banana','cat','REGEX','apple'] +words.sort() +print(words) +**The reason for this type of order is due the ASCII value. +For capital letters its starts from 65 whereas for small letters it starts from 97. From 1408b4cb84a83ac97947a3c6803b27efb8ab042d Mon Sep 17 00:00:00 2001 From: khannariya9 <42000538+khannariya9@users.noreply.github.com> Date: Sun, 19 Apr 2020 17:30:02 +0530 Subject: [PATCH 2/3] Add files via upload --- Riya Khanna/python(5).txt | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Riya Khanna/python(5).txt diff --git a/Riya Khanna/python(5).txt b/Riya Khanna/python(5).txt new file mode 100644 index 0000000..d071e90 --- /dev/null +++ b/Riya Khanna/python(5).txt @@ -0,0 +1,45 @@ +Q1. Make a use of time Module and for loop to print Loading in animated form +Ans1. +import time +print("Loading", end="") +for i in range(0,5): + print(".", end="",flush=True) + time.sleep(1) + + +Q2. Make a digital clock and run it for 5 seconds. +Ans2. +import time + +for i in range(0,6): + localtime = time.localtime() + result = time.strftime("%I:%M:%S %p", localtime) + print(result) + time.sleep(1) + +Q3. Difference between return and yield. +Ans3. +The yield statement suspends function’s execution and sends a value back to the caller, but retains enough state to enable function to resume where it is left off. +When resumed, the function continues execution immediately after the last yield run. +This allows its code to produce a series of values over time, rather than computing them at once and sending them back like a list. +Return sends a specified value back to its caller whereas Yield can produce a sequence of values. +We should use yield when we want to iterate over a sequence, but don’t want to store the entire sequence in memory. + +Q4. Add anything in tuple. +Ans4. +t1=(1,2,3,4) +t2=((5,)) +new=t1[:]+t2[:] +print(new) + +Q5. Whatsapp Texting using webbrowser library. +Ans5. +import webbrowser +import keyboard + +num=int(input("Enter the number you want to send message to: \n")) +message=str(input("Enter your message: \n")) +url=("https://wa.me/"+num+"?text="+message) +webbrowser.open_new_tab(url) +keyboard.press("enter") + From c8dffb29605f56eeb61e7a58d1ffd994996e8f09 Mon Sep 17 00:00:00 2001 From: khannariya9 <42000538+khannariya9@users.noreply.github.com> Date: Sun, 26 Apr 2020 18:53:34 +0530 Subject: [PATCH 3/3] Add files via upload --- Riya Khanna/Pyhthon(6).txt | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Riya Khanna/Pyhthon(6).txt diff --git a/Riya Khanna/Pyhthon(6).txt b/Riya Khanna/Pyhthon(6).txt new file mode 100644 index 0000000..2372af1 --- /dev/null +++ b/Riya Khanna/Pyhthon(6).txt @@ -0,0 +1,70 @@ +Q1.Python Program to read a file line by line and store it in a list. +Ans1. +f1=open("abc.txt",'r') +Lines = f1.readlines() +print(Lines) + +Q2.Python Program to read a file line by line and store it into an array. +Ans2. +def file_read(fname): + arr = [] + with open(fname) as f: + for i in f: + arr.append(i) + print(arr) + print(type(arr)) + +file_read('test.txt') + +Q3.Python program to read a random line from a file. +Ans3. +import random +f=open("abc.txt",'r') +lines = f.readlines() +print(random.choice(lines)) + +Q4.Write a python program to combine each line from the first file with the corresponding line in the second file. +Ans4. +f=open("abc.txt",'r') +f1=open("xyz.txt",'r') +for i,j in zip(f,f1): + print(i+j) + +Q5. Write a Python program to generate 26 text files named A.txt, B.txt and so on. +Ans5. +import string +for i in string.ascii_uppercase: + with open(i + ".txt", "w") as f: + f.writelines(i) +Q6. Write a python program to create a file where all letters of English alphabets are listed by specified numbers of letters in each line. +Ans6. +import string + +def letters_file_line(n): + with open("test.txt", "w") as f: + alphabet = string.ascii_uppercase + letters = [alphabet[i:i + n] + "\n" for i in range(0, len(alphabet), n)] + f.writelines(letters) + +num=int(input("Enter the number: ")) +letters_file_line(num) + +Q7.Scrap data from Worldometer example: INDIA Data and run it on live mode Print additionally total number of CORONAVIRUS Cases, Deaths and Recovered. +Ans7. +import requests +from bs4 import BeautifulSoup +import time +while True: + url='https://www.worldometers.info/coronavirus/country/india' + page=requests.get(url) + page =page.text + + soup=BeautifulSoup(page,'html.parser') + + mess=soup.findAll('h1') + count=soup.findAll('div',{'class':'maincounter-number'}) + mess=mess[1:] + + for i,j in zip(mess,count): + print(f'{i.text} {j.text}') + time.sleep(3600) \ No newline at end of file