diff --git a/Parmanand saraswat/Data Science/assignment1.docx b/Parmanand saraswat/Data Science/assignment1.docx new file mode 100644 index 0000000..6e6c573 Binary files /dev/null and b/Parmanand saraswat/Data Science/assignment1.docx differ diff --git a/Parmanand saraswat/Late night task.txt b/Parmanand saraswat/Late night task.txt new file mode 100644 index 0000000..c2af6a7 --- /dev/null +++ b/Parmanand saraswat/Late night task.txt @@ -0,0 +1,38 @@ +Python Late-Night Task + +1. Make a script to send “Hi” 5 times to a friend. +Sol. +import webbrowser as web +import pyautogui as pg +import time +count = 0 +number=int(input("Enter the number with country code as prefix: ")) +while count<5: + web.open('https://web.whatsapp.com/send?phone='+str(number)+'&text=Hi') + time.sleep(30) + pg.press('enter') + time.sleep(3) + pg.hotkey('ctrl','w') + count += 1 + +2. Make a script to send same message to 6 persons +Sol. +import webbrowser as web +import pyautogui as pg +import time +numbers = [] +count=0 +while count<6: + num=input("Enter "+str(count)+" numbers to send message to: ") + numbers.append(num) + count+=1 +count=1 +url1 = 'https://web.whatsapp.com/send?phone=' +url2 = ',&text=Hi' +for i in numbers: + web.open(url1+i+url2+' You are '+str(count)+' person') + time.sleep(15) + count+=1 + pg.press('enter') + time.sleep(3) + pg.hotkey('ctrl','w') \ No newline at end of file diff --git a/Parmanand saraswat/Linux/assignment1.txt b/Parmanand saraswat/Linux/assignment1.txt new file mode 100644 index 0000000..942879f --- /dev/null +++ b/Parmanand saraswat/Linux/assignment1.txt @@ -0,0 +1,17 @@ +1) When we create a user, some hidden files are generated in the directory of the same user at that time. How is it done ? + +Ans. It is done because these files are in the folder /etc/skel and whichever files we place in this folder those files will be + made available in the home directory of all the users which we create afterwards. + For reference following are some commands to create a file in /etc/skel and creating and listing files in /home/user + files + -> cd /etc/root + -> touch TestFile + -> useradd RedhatUser + -> ls /home/RedhatUser + Now you'll find the TestFile document in this folder which is the proof that whichever files we put in the folder + /etc/skel will be available to all the users created after it. + + +2) Make sub directories inside a parent directory by using single mkdir command. + +Ans. mkdir -p A/B/C (-p for parent directoy option). \ No newline at end of file diff --git a/Parmanand saraswat/Linux/assignment2.txt b/Parmanand saraswat/Linux/assignment2.txt new file mode 100644 index 0000000..7411da1 --- /dev/null +++ b/Parmanand saraswat/Linux/assignment2.txt @@ -0,0 +1,23 @@ +Ans 1 Go to vim /etc/bashrc + Go to line no 73 in RHEL 7 + OR + You can go to /etc/profile and go to line no 62 + Change the umask value whichever you want + Save and exit file with :wq. + +Ans 2 Add an entry for the user in /etc/passwd file. + Add an entry for the group in /etc/group file. + Create the home directory for the added user. + Set the new user password using the passwd command. + +Ans 3 No, we cannot change the umask value to 0888 because if we use it then by default permission for + file and directory go to negative or less than zero that is not possible. + +Ans 4 # useradd -u 1345 username. + To check unique id of that user : + Go to vim /etc/passwd + +Ans 5 #chgrp groupname file/directory + 5(a) To check the groupname of files inside folder + #ll file/folder + 5(b) #chown -R :groupname ParentDirectory (-R for Recursively) \ No newline at end of file diff --git a/Parmanand saraswat/Linux/assignment3.txt b/Parmanand saraswat/Linux/assignment3.txt new file mode 100644 index 0000000..a69c08d --- /dev/null +++ b/Parmanand saraswat/Linux/assignment3.txt @@ -0,0 +1,7 @@ +Ans 1 #tar -cvzf ContentFile.tar.bz2 content.txt. + +Ans 2 #bzip2 -d filename.bz2 (-d specifies Decompress). + +Ans 3 #cat < file. + +Ans 4 #useradd -s /bin/sh username. \ No newline at end of file diff --git a/Parmanand saraswat/python/Assignment1.txt b/Parmanand saraswat/python/Assignment1.txt new file mode 100644 index 0000000..597fd39 --- /dev/null +++ b/Parmanand saraswat/python/Assignment1.txt @@ -0,0 +1,30 @@ +Q1. What is Jpython and Cpython? +ANS:- Cpython is standard implementation of Python which is written in C.We call it Cpython to distinguish Python implementation + of the language engine from Python programming language itself.It is ends up producing bytecode(machine instruction set) + which is Python specific and then executes it.The reason to convert Python code to a bytecode because it's easier to + imolement an interpreter if it is looks like machine instructions. + Jpython is the other implementation of Python which is implemented for Java. Jpython is used to converts Python code + in Java bytecode so it can be implemented in JVM. JVM is used to converts Java code in machine language and executes it. + +Q2. What is difference between Python2 and Python3? +ANS:- PYTHON 2 PYTHON 3 + 1. In Python2, print statement is used to print 1. In python3, print function is used to print any + data. data. + Ex:- print "hello" Ex:- print("hello") + 2. In this version of Python xrange() function 2. range() function is used for iterations. + is uses for iterations. + 3. Default storing of string is ASCII code. To 3. Default storing of string is unicode. + store Unicode string value, you require to + define them with "u". + 4. Exceptions should be enclosed in notations. 4. Exceptions should be enclosed in parenthesis. + 5. Value of global value can be changed while 5. Value of variable snever changed. + using it inside for loop. + 6. Whenever two integer are divided, you get a 6. Whenever two integer are divided, you get a float value. + int value. + +Q3. What is difference between unicode and ASCII code? +ANS:-ASCII Extended solves the problem for languages that are based on the Latin alphabet. + ASCII defines 128 characters, which map to the numbers 0–127. + Unicode sis used to solve the problem for all type of languages.Unicode is superst of ASCII code. + And the numbers 0–127 have the same meaning in ASCII as they have in Unicode. For example, the number + 65 means "Latin capital 'A'". \ No newline at end of file diff --git a/Parmanand saraswat/python/Assignment2.txt b/Parmanand saraswat/python/Assignment2.txt new file mode 100644 index 0000000..c6403ba --- /dev/null +++ b/Parmanand saraswat/python/Assignment2.txt @@ -0,0 +1,132 @@ +Q1. What should be the output? ( 3 + 4 ** 6 - 9 * 10 / 2 ) +ANS:- we know the precence order for arithmetic operators (*,/,+,-) + output = 4054.0 + +Q2. Let say I have, some string "hello this side regex" + Find out the count of the total vowels +? vowels - ['a','e','i','o','u'] +ANS:- + string="hello this side regex" + vowels = ['a','e','i','o','u'] + count=0 + l=list() + for i in string.replace(" ",""): + l.append(i) + for k in l: + if k in vowels: + count+=1 + print(count) + + OUTPUT:- 7 + +Q3. Find out the area of triangle + - 1/2 * b * h (formula of area) + - You have to take value from user about the base, & the height +ANS:- b,h=input("enter value of base and height").split() + print(1/2*int(b)*int(h)) + + OUTPUT:-enter value of length and height5 6 + 15.0 + +Q4. Print the calendar on the terminal. If you give the year. + - Allow the user to input the year. + - Then should that calendar of that year +ANS:- import calendar + year=int(input("enter a year")) + for i in range(1,13): + print(calendar.month(year,i)) + OUTPUT:- January 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 + 4 5 6 7 8 9 10 +11 12 13 14 15 16 17 +18 19 20 21 22 23 24 +25 26 27 28 29 30 31 + + February 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 5 6 7 + 8 9 10 11 12 13 14 +15 16 17 18 19 20 21 +22 23 24 25 26 27 28 + + March 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 5 6 7 + 8 9 10 11 12 13 14 +15 16 17 18 19 20 21 +22 23 24 25 26 27 28 +29 30 31 + + April 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 + 5 6 7 8 9 10 11 +12 13 14 15 16 17 18 +19 20 21 22 23 24 25 +26 27 28 29 30 + + May 2021 +Mo Tu We Th Fr Sa Su + 1 2 + 3 4 5 6 7 8 9 +10 11 12 13 14 15 16 +17 18 19 20 21 22 23 +24 25 26 27 28 29 30 +31 + + June 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 5 6 + 7 8 9 10 11 12 13 +14 15 16 17 18 19 20 +21 22 23 24 25 26 27 +28 29 30 + + July 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 + 5 6 7 8 9 10 11 +12 13 14 15 16 17 18 +19 20 21 22 23 24 25 +26 27 28 29 30 31 + + August 2021 +Mo Tu We Th Fr Sa Su + 1 + 2 3 4 5 6 7 8 + 9 10 11 12 13 14 15 +16 17 18 19 20 21 22 +23 24 25 26 27 28 29 +30 31 + + September 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 5 + 6 7 8 9 10 11 12 +13 14 15 16 17 18 19 +20 21 22 23 24 25 26 +27 28 29 30 + + October 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 + 4 5 6 7 8 9 10 +11 12 13 14 15 16 17 +18 19 20 21 22 23 24 +25 26 27 28 29 30 31 + + November 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 5 6 7 + 8 9 10 11 12 13 14 +15 16 17 18 19 20 21 +22 23 24 25 26 27 28 +29 30 + + December 2021 +Mo Tu We Th Fr Sa Su + 1 2 3 4 5 + 6 7 8 9 10 11 12 +13 14 15 16 17 18 19 +20 21 22 23 24 25 26 \ No newline at end of file diff --git a/Parmanand saraswat/python/Assignment3.txt b/Parmanand saraswat/python/Assignment3.txt new file mode 100644 index 0000000..4acd035 --- /dev/null +++ b/Parmanand saraswat/python/Assignment3.txt @@ -0,0 +1,46 @@ +Q1. Find the Armstrong Number between the two numbers which are input by user + ? Armstrong number : 153 -> 1*1*1 + 5*5*5 + 3*3*3 +ANS:-m=int(input("enter number1 :")) + n=int(input("enter number2 :")) + for num in range(m,n+1): + sum=0 + temp=num + while temp>0: + rem=temp%10 + sum+=rem**3 + temp=temp/10 + if num==sum: + print(num) + else: + continue + + OUTPUT:-enter number1 :151 + enter number2 :154 + 153 + +Q2. Let’s say you have a string “hello this world @2020!!! ” + ? Remove the punctuation like [“@!#$%&*()”] from the string + ¦ Final output should be without the punctuation + ? “hello this world 2020” +ANS:- string=input("enter your string :") + for i in string: + if i.isalnum() or i==' ': + print(i,end="") + + OUTPUT:-enter your string :hello this world @2020!!! + hello this world 2020 + +Q3. You have a list with words - [“Apple”, “banana”, “cat”, “REGEX”,”apple”] + ? Sort words in Alphabetical order + ¦ If you get output, like [Apple, apple, banana] + ? How has it happened? +ANS:- + l=["Apple", "banana", "cat", "REGEX","apple"] + print(sorted(l)) #we also can use here l.sort() and then print(l) + + OUTPUT:- ['Apple', 'REGEX', 'apple', 'banana', 'cat'] + + REASON:-- Python put uppercase items first because the ASCII value(Python2) or unicode(Python3) value for + uppercase items is less than lowercase items. And hence if we sort them in increasing order, the + upper case will come before the lower case. + \ No newline at end of file diff --git a/Parmanand saraswat/python/Assignment4.txt b/Parmanand saraswat/python/Assignment4.txt new file mode 100644 index 0000000..a92750a --- /dev/null +++ b/Parmanand saraswat/python/Assignment4.txt @@ -0,0 +1,103 @@ +# Ques1 : Write a Program to print new list which contains all the first Characters of strings present in a list + # LIST_STATES = ["GOA","RAJASTHAN","KARNATAKA","GUJRAT","MANIPUR","MADHYA PRADESH"] +# Ans : +List_states = ["GOA","RAJASTHAN","KARNATAKA","GUJRAT","MANIPUR","MADHYA PRADESH"] +New_list = [] +for i in List_states: + first_char = i[0] + New_list.append(first_char) +print(New_list) + + + +# Ques2 : Write a program to replace each string with an integer value in a given list of strings. + # The replacement integer value should be a sum of AScci values of each character of type corresponding string. + # LIST: ['GAnga', 'Tapti', 'Kaveri', 'Yamuna', 'Narmada' ] +# Ans : +given_list = ['GAnga', 'Tapti', 'Kaveri', 'Yamuna', 'Narmada'] +add = 0 +replaced_list = [] +for i in given_list: + for j in i: + add = add + ord(j) + replaced_list.append(add) +print(replaced_list) + + + +# Ques3 : You have to run your Program at 9:00am. Date: 14th April 2020. + ### HINT: + # You have to use datetime Module or time module. + # You have to convert your output in #LIST_FORMAT + # [ '2020-04-13' , '17:11:01.952975' ] + # you can use this with the help of IF/Else statement +# Ans : +from datetime import datetime +from threading import Timer + +x = datetime.today() + +date = datetime.strptime('2020-04-14',"%Y-%m-%d") +y = date.replace(hour=9, minute=0, second=0, microsecond=0) + +delta_t = y - x + +secs = delta_t.seconds + 1 + +def hello_world(): + print("hello world") + +t = Timer(secs, hello_world) +t.start() + + + +# Ques4 : GIve 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. +# Ans : + + # 1. +given_tuple = ('a','l','g','o','r','i','t','h','m') +print(given_tuple[::]) + + # 2. -> We can't delete the 3rd indexed element from the tuple as TUPLES ARE IMMUTABLE (i.e, we can't change it's contents). + + + +# Ques5: 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 greator then 20 + # - then print those numbers those are less then 10 or equal to 10 + # - store these above two list in two different list. +# Ans: +REGex=[1,2,3,4,5,6,7,8,9,0,77,44,15,33,65,89,12] +list1 = [] +list2 = [] + +# Printing the elements > 20 +print('Elements > 20 :') +for i in REGex: + if(i > 20): + print(i) + + list1.append(i) # adding the element > 20 in list1 + +# Printing the elements <= 10 +print('Elements <= 10 :') +for i in REGex: + if(i <= 10): + print(i) + + list2.append(i) # adding the elemant <= 10 in list2 + +print('list of elements > 20 :',list1,'\nlist of elements <= 10 :',list2) + + + +# Ques6 : Execute standard LINUX Commands using Python Programming. +# Ans: We can execute any LINUX Command using python by using the following - + +import os + +os.system('command to execute') \ No newline at end of file diff --git a/Parmanand saraswat/python/Assignment5.txt b/Parmanand saraswat/python/Assignment5.txt new file mode 100644 index 0000000..f9c847b --- /dev/null +++ b/Parmanand saraswat/python/Assignment5.txt @@ -0,0 +1,97 @@ +1.Write a Python program to read a file line by line and store it into a list. +Sol. +def file_read(fname): + with open(fname) as f: +content_list = f.readlines() + print(content_list) +file_read('test.txt') + + + +2. Write a Python program to read a file line by line store it into an array. +Sol. +def file_read(fname): +content_array = [] + with open(fname) as f: + for line in f: +content_array.append(line) + print(content_array) + print(type(content_array)) +file_read('test.txt' + +3. Write a Python program to read a random line from a file. +Sol. +import random +def random_line(fname): + lines = open(fname).read().splitlines() + return random.choice(lines) +print(random_line('test.txt')) + +4. Write a Python program to combine each line from first file with thecorresponding line in second file +Sol. +print('\n') +with open('test.txt') as fh1, open('test2.txt') as fh2: + for line1, line2 in zip(fh1, fh2): + print(line1+line2) + + + +5. Write a Python program to generate 26 text files named A.txt, B.txt, andso on up to Z.txt. +Sol. +import string +for letter in string.ascii_uppercase: + with open (letter + ".txt", "w") as f: +f.writelines(letter) + + +6. Write a Python program to create a file where all letters of Englishalphabet are listed by specified number of letters on each line. +Sol. +import string +def letters_file_line(n): + with open("words1.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) + + + +7. Scrap data from Worldometer example: INDIA Data and run it on live mode Print additionally total number of CORONAVIRUS Cases, Deaths and Recovered. +Sol. +import urllib.request +from urllib.request import Request +from bs4 import BeautifulSoup + +data=[] +total_data=[] +url="https://www.worldometers.info/coronavirus/" +hdr = {'User-Agent': 'Chrome/80.0.3987.163'} +req = Request(url,headers=hdr) + +r=urllib.request.urlopen(req).read() +soup=BeautifulSoup(r,'lxml') + +divs=soup.findAll("div", {"id": "maincounter-wrap"}) +for tag in divs: +spanTags = tag.find_all("span") + for tag in spanTags: +total_data.append(tag.text) + +print("\n{:>16}TOTAL WORLD DATA\nCORONAVIRUS Cases Total Deaths Total Recovered".format(" ")) +print(" {}{:>15}{:>16}".format(total_data[0],total_data[1],total_data[2])) + +print("\nScrapingWorldometer for Data of Covid19 (India)") + +table=soup.find('table') +table_rows=table.find_all('tr') + +for tr in table_rows: + td=tr.find_all('td') + row=[i.text for i in td] + data.append(row) + +india=data[24] +print("\n{:>16}INDIA COVID19 DATA\nCountry Total Cases New Cases Total Deaths New Deaths Total Recovered Active Cases Serious,Critical Tot Cases/1M pop Deaths/1M pop Total Tests Tests/1M pop".format(" ")) +print("{} {:>11} {:>10} {:>12} {:>20} {:>8} {:>13} {} {:>28} {:>18} {:>15} {:>10}".format(india[0],india[1],india[2],india[3],india[4],india[5],india[6],india[7],india[8],india[9],india[10],india[11],india[12])) +