Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignments #151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Riya Khanna/Linux(4).txt
Original file line number Diff line number Diff line change
@@ -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).
70 changes: 70 additions & 0 deletions Riya Khanna/Pyhthon(6).txt
Original file line number Diff line number Diff line change
@@ -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)
86 changes: 86 additions & 0 deletions Riya Khanna/Python(4).txt
Original file line number Diff line number Diff line change
@@ -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)
38 changes: 38 additions & 0 deletions Riya Khanna/python(3).txt
Original file line number Diff line number Diff line change
@@ -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.
45 changes: 45 additions & 0 deletions Riya Khanna/python(5).txt
Original file line number Diff line number Diff line change
@@ -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")