diff --git a/Priyansh Lakhotia/Linux Task 1/Session #3(Late Night task - Question 2).txt b/Priyansh Lakhotia/Linux Task 1/Session #3(Late Night task - Question 2).txt new file mode 100644 index 0000000..ce0dbb2 --- /dev/null +++ b/Priyansh Lakhotia/Linux Task 1/Session #3(Late Night task - Question 2).txt @@ -0,0 +1,28 @@ +CREATING SUB-DIRECTORY UNDER DIRECTORY USING ONE MKDIR COMMAND + + +priya@ubuntu:~$ pwd +/home/priya +priya@ubuntu:~$ mkdir -p A/B/C +priya@ubuntu:~$ ls +A Documents examples.desktop Pictures priya Desktop Downloads Music Public Templates Videos +priya@ubuntu:~$ cd A +priya@ubuntu:~/A$ ls +B +priya@ubuntu:~/A$ cd B +priya@ubuntu:~/A/B$ ls +C +priya@ubuntu:~/A/B$ + + + + + + + + + + + + + diff --git a/Priyansh Lakhotia/Linux Task 1/Session #3{Late Night task - Question 1).txt b/Priyansh Lakhotia/Linux Task 1/Session #3{Late Night task - Question 1).txt new file mode 100644 index 0000000..a605d24 --- /dev/null +++ b/Priyansh Lakhotia/Linux Task 1/Session #3{Late Night task - Question 1).txt @@ -0,0 +1,3 @@ +Ques: When we create a new user some hidden files are created in the directory of the same user at that time. How is it done ? + +Ans: 'adduser' command reads the content of the /etc/login.defs file. This file contains configuration for the shadow password suite such as password expiration policy, ranges of user IDs used when creating system and regular users and more. So as this file contains login details so some hidden files are created at the time of creating a new user. \ No newline at end of file diff --git a/Priyansh Lakhotia/Linux Task 1/Task-1.txt b/Priyansh Lakhotia/Linux Task 1/Task-1.txt new file mode 100644 index 0000000..a18ca45 --- /dev/null +++ b/Priyansh Lakhotia/Linux Task 1/Task-1.txt @@ -0,0 +1,15 @@ +Task 1 + +Ques: Why a directory of username is not created when we run the command '$ useradd username' in the home whereas it is created when we use the command '$ adduser username' ? + +Ans: By default 'useradd' command creates a user's home directory under /home directory with username. + + +The useradd program has been deprecated in favor of adduser. From man useradd: +useradd is a low level utility for adding users. Administrators should usually use adduser instead. + +adduser is a friendlier frontend to useradd and will do things like create user directories by default. When you run it with only a username as an argument, you will be prompted to provide additional information such as the password + +In general, you should always use adduser instead of useradd since this will also set up the required groups automatically. As explained in man adduser: + +"adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level tools like useradd, groupadd and usermod programs, by default choosing Debian policy conformant UID and GID values, creating a home directory with skeletal configuration, running a custom script, and other features. " \ No newline at end of file diff --git a/Priyansh Lakhotia/Linux Task 2/Session 4-Task 2.txt.txt b/Priyansh Lakhotia/Linux Task 2/Session 4-Task 2.txt.txt new file mode 100644 index 0000000..aff3f1c --- /dev/null +++ b/Priyansh Lakhotia/Linux Task 2/Session 4-Task 2.txt.txt @@ -0,0 +1,82 @@ +Ques 1: How can you change the umask value permanently ? + +Ans 1: This can be achived by writing a new Umask value in your shell’s configuration file (~/.bashrc for Bash) or in the /etc/profile file. + + +Ques 2:Add a new user without using adduser or useradd commands + +Ans: +Step 1:Add an entry for the user in /etc/passwd file. +Step 2:Add an entry for the group in /etc/group file. +Step 3:Create the home directory for the added user. +Step 4:Set the new user password using the passwd command. + + + +Ques 3:Can we change the UMASK value to 0888? + +Ans 3: No we cannot change the value of UMASK to 0888 because the maximum value of UMASK can be 0777. +Even if we try to do so than we will get the following error: + +priya@ubuntu:~$ umask 0888 +bash: umask: 0888: octal number out of range +priya@ubuntu:~$ + + + +Ques 4: New user with unique user id +Ans 4: We can create new user with unique userid with ‘-u‘ option. For example, the following command will create a user ‘superuser‘ with custom userid ‘888‘. +And also we can verify the user with the command cat /etc/passwd | grep superuser. +Code: + +priya@ubuntu:~$ sudo -i +[sudo] password for priya: +root@ubuntu:~# useradd -u 888 superuser +root@ubuntu:~# cat /etc/passwd | grep superuser +superuser:x:888:1003::/home/superuser:/bin/sh +root@ubuntu:~# + + + + +Ques 5:How can we change group of a file? + +Ans: The chgrp command changes the group ownership of given files. +command - $ chgrp newgroupname filename + +Ques 5(a):To check the group name of a file + +Ans: By using the command + $ ls -l filename + + +Ques 5(b): Changing the group of the folder and the files present in the same folder using a simple command + +Ans 5(b): This can be done by using a command: + + $ sudo chgrp -r groupname filename + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Priyansh Lakhotia/Linux Task 3/sesssion #5 - Task 3.txt.txt b/Priyansh Lakhotia/Linux Task 3/sesssion #5 - Task 3.txt.txt new file mode 100644 index 0000000..3e63aeb --- /dev/null +++ b/Priyansh Lakhotia/Linux Task 3/sesssion #5 - Task 3.txt.txt @@ -0,0 +1,144 @@ +Ques 1: How to create a new user and at the same time define a pre-existing group to it ? + +Ans 1: This can be achived by using the command + + sudo adduser -g username groupname +(this groupname can be existing) + + + +Ques 2:How to unzip the bz2 file + +Ans 2: bz2 file is unzipped using + $ bzip2 -d filename.bz2 +(here d means decompress) + +e.g., + +priya@ubuntu:~/shubh$ ls -lh +total 50M +-rwxrwxrw- 1 priya priya 50M Apr 8 12:46 1 +-r--r---w- 1 priya priya 0 Apr 8 10:56 11 +-rw-r--r-- 1 priya priya 0 Apr 7 13:58 file +dr--rw---x 2 priya priya 4.0K Apr 7 14:04 folder +dr-xr---wx 2 priya priya 4.0K Apr 8 10:56 hello +priya@ubuntu:~/priya$ yes "Priyansh" >> 11 +bash: 11: Permission denied +priya@ubuntu:~/priya$ cat 11 +priyaz@ubuntu:~/priya$ yes "Priyansh" >> 11 +bash: 11: Permission denied +priya@ubuntu:~/priya$ yes "Priyansh" > 11 +bash: 11: Permission denied +priya@ubuntu:~/priya$ touch 12 +priya@ubuntu:~/priya$ yes "Priyansh" > 12 +^C +priya@ubuntu:~/priya$ ls -lh +total 89M +-rwxrwxrw- 1 priya priya 50M Apr 8 12:46 1 +-r--r---w- 1 priya priya 0 Apr 8 10:56 11 +-rw-r--r-- 1 priya priya 40M Apr 8 12:48 12 +-rw-r--r-- 1 priya spriya 0 Apr 7 13:58 file +dr--rw---x 2 priya priya 4.0K Apr 7 14:04 folder +dr-xr---wx 2 priya priya 4.0K Apr 8 10:56 hello +priya@ubuntu:~/shubh$ bzip2 1 +priya@ubuntu:~/shubh$ ls -lh +total 40M +-r--r---w- 1 priya priya 0 Apr 8 10:56 11 +-rw-r--r-- 1 priya priya 40M Apr 8 12:48 12 +-rwxrwxrw- 1 priya priya 4.5K Apr 8 12:46 1.bz2 +-rw-r--r-- 1 priya priya 0 Apr 7 13:58 file +dr--rw---x 2 priya priya 4.0K Apr 7 14:04 folder +dr-xr---wx 2 priya priya 4.0K Apr 8 10:56 hello +priya@ubuntu:~/priya$ bzip2 -d 1.bz2 +priya@ubuntu:~/priya$ ls +1 11 12 file folder hello +priya@ubuntu:~/priya$ + + +Ques 3 : Archive and compress files with data and folder using bz2 extension + +Ans 3:This can be achived by using the command + $ tar -cvzf filename.tar.bz2 file1name file2name foldername + +priya@ubuntu:~$ cd shubh +priya@ubuntu:~/shubh$ mkdir newfolder +priya@ubuntu:~/shubh$ cd newfolder +priya@ubuntu:~/shubh/newfolder$ touch newfile1 +priya@ubuntu:~/shubh/newfolder$ touch newfile2 +priya@ubuntu:~/shubh/newfolder$ ls +newfile1 newfile2 +priya@ubuntu:~/shubh/newfolder$ cd .. +priya@ubuntu:~/shubh$ ls +1 11 12 file folder hello newfolder +priya@ubuntu:~/shubh$ tar -cvzf compressed.tar.bz2 1 12 newfolder +1 +12 +newfolder/ +newfolder/newfile1 +newfolder/newfile2 +priya@ubuntu:~/priya$ ls +1 11 12 compressed.tar.bz2 file folder hello newfolder +priya@ubuntu:~/priya$ + + + +Ques 4 :How can we add a user and at the same time define its shell as /bin/bash. +Ans 4 : This can be achived by using the command: + $ sudo useradd -s /bin/bash username + +priya@ubuntu:~/priya$ cat /etc/shells +# /etc/shells: valid login shells +/bin/sh +/bin/bash +/bin/rbash +/bin/dash +priya@ubuntu:~/shubh$ sudo useradd -s /bin/bash spiderman +[sudo] password for priya: +priya@ubuntu:~/shubh$ cat /etc/passwd +root:x:0:0:root:/root:/bin/bash +daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin +bin:x:2:2:bin:/bin:/usr/sbin/nologin +sys:x:3:3:sys:/dev:/usr/sbin/nologin +sync:x:4:65534:sync:/bin:/bin/sync +games:x:5:60:games:/usr/games:/usr/sbin/nologin +man:x:6:12:man:/var/cache/man:/usr/sbin/nologin +lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin +mail:x:8:8:mail:/var/mail:/usr/sbin/nologin +news:x:9:9:news:/var/spool/news:/usr/sbin/nologin +uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin +proxy:x:13:13:proxy:/bin:/usr/sbin/nologin +www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin +backup:x:34:34:backup:/var/backups:/usr/sbin/nologin +list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin +irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin +gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin +nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin +systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin +systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin +syslog:x:102:106::/home/syslog:/usr/sbin/nologin +messagebus:x:103:107::/nonexistent:/usr/sbin/nologin +_apt:x:104:65534::/nonexistent:/usr/sbin/nologin +uuidd:x:105:111::/run/uuidd:/usr/sbin/nologin +avahi-autoipd:x:106:112:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/usr/sbin/nologin +usbmux:x:107:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin +dnsmasq:x:108:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin +rtkit:x:109:114:RealtimeKit,,,:/proc:/usr/sbin/nologin +cups-pk-helper:x:110:116:user for cups-pk-helper service,,,:/home/cups-pk-helper:/usr/sbin/nologin +speech-dispatcher:x:111:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false +whoopsie:x:112:117::/nonexistent:/bin/false +kernoops:x:113:65534:Kernel Oops Tracking Daemon,,,:/:/usr/sbin/nologin +saned:x:114:119::/var/lib/saned:/usr/sbin/nologin +pulse:x:115:120:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin +avahi:x:116:122:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/usr/sbin/nologin +colord:x:117:123:colord colour management daemon,,,:/var/lib/colord:/usr/sbin/nologin +hplip:x:118:7:HPLIP system user,,,:/var/run/hplip:/bin/false +geoclue:x:119:124::/var/lib/geoclue:/usr/sbin/nologin +gnome-initial-setup:x:120:65534::/run/gnome-initial-setup/:/bin/false +gdm:x:121:125:Gnome Display Manager:/var/lib/gdm3:/bin/false +shubhangvats:x:1000:1000:Shubhang Vats,,,:/home/shubhangvats:/bin/bash +yash:x:1001:1001:,,,:/home/yash:/bin/bash +regex:x:999:1002::/home/regex:/bin/sh +superuser:x:888:1003::/home/superuser:/bin/sh +vats:x:1002:1004:,,,:/home/vats:/bin/bash +spiderman:x:1003:1005::/home/spiderman:/bin/bash +priya@ubuntu:~/shubh$ diff --git a/Priyansh Lakhotia/Python Task 1/Python Session 1(Task 1).txt b/Priyansh Lakhotia/Python Task 1/Python Session 1(Task 1).txt new file mode 100644 index 0000000..0538207 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 1/Python Session 1(Task 1).txt @@ -0,0 +1,35 @@ +Assignment 1 - Unicode vs ASCII + +ASCII and Unicode are two character encodings. They are standards on how to represent different characters in binary so that they can be written, stored, transmitted, and read in digital media. The main difference between the two is in the way they encode the character and the number of bits that they use for each. ASCII originally used seven bits to encode each character. This was later increased to eight with Extended ASCII to address the apparent inadequacy of the original. In contrast, Unicode uses a variable bit encoding program where you can choose between 32, 16, and 8-bit encodings. Using more bits lets you use more characters at the expense of larger files while fewer bits give you a limited choice but you save a lot of space. Using fewer bits (i.e. UTF-8 or ASCII) would probably be best if you are encoding a large document in English. + +One of the main reasons why Unicode was the problem arose from the many non-standard extended ASCII programs. Unless you are using the prevalent page, which is used by Microsoft and most other software companies, then you are likely to encounter problems with your characters appearing as boxes. Unicode virtually eliminates this problem as all the character code points were standardized. + + + + + +Assignment 2 - Different types of Python Compilers: + +The different types of Python compilers are : + +1) CPython. +It is the most widely used interpreter in Python. Developed in C and Python, the bindings for the interpreter must be written in a foreign language other than Python. CPython uses a Global Interpreter Lock (GIL) on each process. Thus Python bytecode for a single process is executed on a single thread. + +2) Jython or Jpython. +Jython is an implementation that has been designed for the seamless integration of Python code over JVM. The advantage of this integration is that it provides an opportunity for amalgamation of a popular scripting language like python to a vast library of the JVM. Jython compiles files to .class extensions. + +3)IronPython. +Iron Python is a python implementation designed with the target of the dot net framework. This project is maintained presently by a small community of users in Github. To be used for scripting this has a requisite of installing the Python tools for visual studio which is available as an extension for visual studio IDE. The full implementation is written in C#. + +4)ActivePython. +ActivePython is a commercial version of Python scripting platform designed and developed by the Open source organization called ActiveState. It provides Python bundles along with some additional packages. + + +5)PyJS (it also is formerly known as Pyjamas). +PyJs is a rich internet application particularly used in the development of client-side web applications and desktop applications using Python scripting. The PyJs has a compiler that translates Python to JavaScript and is primarily designed over the Ajax framework. + +6)Nuitka. +Nuitka is an ideal example of a source to source compiler. The compiler allows the user to feed python codes and produce C/C++ extensions even if the computer has no python version installed in it. + +7)Stackless Python +It is an advanced version of programming language interpreter used by the developers in multithreaded programming without compromising on performance complexity and performance issues faced by the conventional multithreaded programming languages. \ No newline at end of file diff --git a/Priyansh Lakhotia/Python Task 2/question1.py b/Priyansh Lakhotia/Python Task 2/question1.py new file mode 100644 index 0000000..cb72387 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 2/question1.py @@ -0,0 +1,8 @@ +# What should be the output of ( 3 + 4 ** 6 - 9 * 10 / 2 ) ? + +#Solution: + +a = (3+4**6-9*10/2) +print (a) + +#Answer is 4054.0 diff --git a/Priyansh Lakhotia/Python Task 2/question2.py b/Priyansh Lakhotia/Python Task 2/question2.py new file mode 100644 index 0000000..42ff498 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 2/question2.py @@ -0,0 +1,14 @@ +# Question 2 +''' +Lets say I have some string "hello this side regex" + Find out the count of the total vowels + vowels - ['a','e','i','o','u'] +''' + +vowels = ['a','e','i','o','u'] +text = ("hello this side regex") +total_vowels = 0 +for i in text: + if i in vowels: + total_vowels = (total_vowels + 1) +print (total_vowels) diff --git a/Priyansh Lakhotia/Python Task 2/question3.py b/Priyansh Lakhotia/Python Task 2/question3.py new file mode 100644 index 0000000..3b166f0 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 2/question3.py @@ -0,0 +1,13 @@ +#Question 3 +''' +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 +''' + + +base = int(input("Enter the length of the base of the triangle: ")) +height = int(input("Enter the height of the triangle: ")) +area = (0.5 * base * height) +print ("Area of the triangle is ", area) + diff --git a/Priyansh Lakhotia/Python Task 2/question4.py b/Priyansh Lakhotia/Python Task 2/question4.py new file mode 100644 index 0000000..ba42ae6 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 2/question4.py @@ -0,0 +1,11 @@ +# Question 4 +''' +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 +''' + +import calendar +year = int(input("Enter year: ")) +print("The calendar of year ",year, " is: ") +print(calendar.calendar(year)) diff --git a/Priyansh Lakhotia/Python Task 3/question1.py b/Priyansh Lakhotia/Python Task 3/question1.py new file mode 100644 index 0000000..76e9230 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 3/question1.py @@ -0,0 +1,21 @@ +# Question 1 +''' +Find the Armstrong Number between the two numbers which are input by user + Note: Armstrong number : 153 -> 1*1*1 + 5*5*5 + 3*3*3 +''' +#Solution: + +number1 = int(input("Enter the starting number")) +number2 = int(input("Enter the ending number")) + +for i in range(number1, number2 + 1): + sum = 0 + temp = i + while temp > 0: + digit = temp % 10 + sum = sum + digit ** 3 + temp = temp // 10 + if i == sum: + print (i) + + diff --git a/Priyansh Lakhotia/Python Task 3/question2.py b/Priyansh Lakhotia/Python Task 3/question2.py new file mode 100644 index 0000000..204185d --- /dev/null +++ b/Priyansh Lakhotia/Python Task 3/question2.py @@ -0,0 +1,15 @@ +# Question 2 +''' +Lets 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” +''' +#Solution : +s = ("hello this world @2020!!! ") +final_output=('') +punc = ['@', '!', '#', '$', '%', '&', '*', '(', ')'] +for i in s: + if i not in punc: + final_output = final_output + i +print (final_output) diff --git a/Priyansh Lakhotia/Python Task 3/question3.py b/Priyansh Lakhotia/Python Task 3/question3.py new file mode 100644 index 0000000..fc86c6e --- /dev/null +++ b/Priyansh Lakhotia/Python Task 3/question3.py @@ -0,0 +1,21 @@ +# Question 3 + +''' +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? +''' + +#Solution: + +ls = ["Apple", "banana", "cat", "REGEX","apple"] +sortls = sorted(ls) +print (sortls) + + + +''' +This happens because as per the ASCII encoding, the CAPITAL LETTERS have a smaller value than the small letters and as such, when arranged in alphabetical order (which uses the ASCII value as its ordering basis), the CAPITAL LETTERS appear first. +''' + diff --git a/Priyansh Lakhotia/Python Task 4/question1.py b/Priyansh Lakhotia/Python Task 4/question1.py new file mode 100644 index 0000000..b06b711 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 4/question1.py @@ -0,0 +1,19 @@ +# Question-1 + +''' +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"] + +''' + +LIST_STATES = ["GOA","RAJASTHAN","KARNATAKA","GUJRAT","MANIPUR","MADHYA PRADESH"] + + +new_list = [] + +for i in LIST_STATES: + new_list.append(i[0]) + +print(new_list) + diff --git a/Priyansh Lakhotia/Python Task 4/question2.py b/Priyansh Lakhotia/Python Task 4/question2.py new file mode 100644 index 0000000..77b06bd --- /dev/null +++ b/Priyansh Lakhotia/Python Task 4/question2.py @@ -0,0 +1,18 @@ +# Question-2 + +''' +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' ] +''' + +LIST = ['GAnga', 'Tapti', 'Kaveri', 'Yamuna', 'Narmada' ] + +ls = [] +add = 0 +for i in LIST: + for j in i: + add = add + ord(j) + ls.append(add) +ls \ No newline at end of file diff --git a/Priyansh Lakhotia/Python Task 4/question3.py b/Priyansh Lakhotia/Python Task 4/question3.py new file mode 100644 index 0000000..6f4b2e1 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 4/question3.py @@ -0,0 +1,35 @@ +# Question-3 + +''' +3. ###### 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 helf of IF/Else statement +''' + + + +import datetime +x = datetime.datetime.now() + +# converting the time to a list +a = str(x) +ls = a.split(" ") + + + +# running program at 09:00 AM Date 14th April 2020 +import time +while True: + x = time.ctime() + ls = x.split(" ") + print(ls) + if ls == ['Wed', 'Apr', '15', '15:08:03', '2020']: + print("This is the time") + break + else: + continue + + diff --git a/Priyansh Lakhotia/Python Task 4/question4.py b/Priyansh Lakhotia/Python Task 4/question4.py new file mode 100644 index 0000000..c26ffea --- /dev/null +++ b/Priyansh Lakhotia/Python Task 4/question4.py @@ -0,0 +1,14 @@ +# Question - 4 + +''' +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. + +''' + +t = ('a','l','g','o','r','i','t','h','m') + +for i in range(9): + print(t[i]) \ No newline at end of file diff --git a/Priyansh Lakhotia/Python Task 4/question5.py b/Priyansh Lakhotia/Python Task 4/question5.py new file mode 100644 index 0000000..a1c5f16 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 4/question5.py @@ -0,0 +1,22 @@ +# Question - 5 + +''' +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. + +''' +a=[] #list of those numbers greator then 20 +b=[] #list of those numbers those are less then 10 or equal to 10 + +REGex=[1,2,3,4,5,6,7,8,9,0,77,44,15,33,65,89,12] +for i in REGex: + if i>20: + a.append(i) + elif i <= 10: + b.append(i) + +print(a) #list of those numbers greator then 20 + +print(b) #list of those numbers those are less then 10 or equal to 10 diff --git a/Priyansh Lakhotia/Python Task 5/question1.py b/Priyansh Lakhotia/Python Task 5/question1.py new file mode 100644 index 0000000..77f3217 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 5/question1.py @@ -0,0 +1,22 @@ +# Question-1 + +''' +1. Hint: + -> Make a use of Time Module and for Loop + -> Output Should be : + Loading. + Loading.. + Loading... + Loading.... + Loading..... + Here it shows you 5 output but you have to print only "Loading....." in animated form. +''' + +#Solution: +import time +print("Loading", end = "") +i = 1 +while(i < 6): + print('.', end = "") + time.sleep(1) + i += 1 diff --git a/Priyansh Lakhotia/Python Task 5/question2.txt b/Priyansh Lakhotia/Python Task 5/question2.txt new file mode 100644 index 0000000..07ada89 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 5/question2.txt @@ -0,0 +1,12 @@ +Question - 2 What is the difference between Return and Yield ? + + + +Answer: +The yield statement is used in Python generators to replace the return of a function to send a value back to its caller without destroying local variables. A generator is a special function in Python that returns a generator object to the caller rather than a data value. +The return statement, unlike the yield statement, exits from a function, handing back a value to its caller. Typically, a return statement appears at the very end of a function block to return the final result of executing all statements contained in that function. All functions return a value and if there is no value specified, it will return “None”. + +Generators vs. Functions in Python Yield and Return + +The yield statement is explicitly used with Python generators. Syntactically, a generator is a function with a yield statement. While a function can have multiple return statements, only one of them can be called for any given invocation of the function. +Unlike a function which only returns once, generators can halt execution and yield intermediate results. Each generator is defined as a function, but instead of the return keyword, yield keyword is used inside the function block to indicate that the return value is only temporary and the whole generator can be resumed even after the return value is obtained. \ No newline at end of file diff --git a/Priyansh Lakhotia/Python Task 5/question3.py b/Priyansh Lakhotia/Python Task 5/question3.py new file mode 100644 index 0000000..4c7d524 --- /dev/null +++ b/Priyansh Lakhotia/Python Task 5/question3.py @@ -0,0 +1,23 @@ +# Question - 3 + +''' + +3. Make digital Clock and run it for 5 sec. + Output: + 16:39:08 + :09 + :10 + :11 + :12 +''' + + +#Solution: + +import time +i=0 +while i < 5: + t = time.ctime() + print(t[11:19]) + time.sleep(1) + i = (i+1) diff --git a/Priyansh Lakhotia/Python Task 5/question4.py b/Priyansh Lakhotia/Python Task 5/question4.py new file mode 100644 index 0000000..f91092d --- /dev/null +++ b/Priyansh Lakhotia/Python Task 5/question4.py @@ -0,0 +1,14 @@ +# Question - 4 + + +""" +4. Add anything in tuple.. example: (1,2,3,4) -> new tuple (1,2,3,4,5) +""" + + +#Solution: + +t1 = (1,2,3,4) +t2= (5,) #Since a single element is in tuple so a comma(,) is required after it +t3 = t1 + t2 +print(t3) diff --git a/Priyansh Lakhotia/Python Task 5/question5.py b/Priyansh Lakhotia/Python Task 5/question5.py new file mode 100644 index 0000000..58a7b4f --- /dev/null +++ b/Priyansh Lakhotia/Python Task 5/question5.py @@ -0,0 +1,43 @@ +# Question - 5 + + +""" +WhatsApp texting using webbrowser Lib. +""" + +#Solution: + +import webbrowser as wb +import time +import pyautogui as g +send = False +print(time.ctime()) +number = int(input("Enter the number to send message: ")) +message = input("Enter your message") +YourTime = input("Enter time to send message(hh:mm:ss): ") +print(time.ctime()) +while(True): + t = time.ctime() + str(t) + a = t.split(" ") + if a[3] == YourTime: + send = True + if send == True: + print("send") + send = False + time.sleep(1) + url = 'https://wa.me/'+str(number)+'?text='+str(message) + print(url) + wb.open(url) + time.sleep(5) + g.moveTo(670, 315) + g.click() + time.sleep(5) + g.moveTo(698, 394) # for using watsapp web + g.click() + time.sleep(10) + g.press('enter') + print("Task Complete") + break + + diff --git a/Priyansh Lakhotia/Python-Task 6/A.txt b/Priyansh Lakhotia/Python-Task 6/A.txt new file mode 100644 index 0000000..d54596c --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/A.txt @@ -0,0 +1 @@ +AFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/B.txt b/Priyansh Lakhotia/Python-Task 6/B.txt new file mode 100644 index 0000000..171811f --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/B.txt @@ -0,0 +1 @@ +BFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/C.txt b/Priyansh Lakhotia/Python-Task 6/C.txt new file mode 100644 index 0000000..4eaed00 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/C.txt @@ -0,0 +1 @@ +CFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/D.txt b/Priyansh Lakhotia/Python-Task 6/D.txt new file mode 100644 index 0000000..8c56d8c --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/D.txt @@ -0,0 +1 @@ +DFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/E.txt b/Priyansh Lakhotia/Python-Task 6/E.txt new file mode 100644 index 0000000..b48b673 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/E.txt @@ -0,0 +1 @@ +EFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/F.txt b/Priyansh Lakhotia/Python-Task 6/F.txt new file mode 100644 index 0000000..157603c --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/F.txt @@ -0,0 +1 @@ +FFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/G.txt b/Priyansh Lakhotia/Python-Task 6/G.txt new file mode 100644 index 0000000..cc8b000 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/G.txt @@ -0,0 +1 @@ +GFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/H.txt b/Priyansh Lakhotia/Python-Task 6/H.txt new file mode 100644 index 0000000..e4ea551 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/H.txt @@ -0,0 +1 @@ +HFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/I.txt b/Priyansh Lakhotia/Python-Task 6/I.txt new file mode 100644 index 0000000..b57e701 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/I.txt @@ -0,0 +1 @@ +IFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/J.txt b/Priyansh Lakhotia/Python-Task 6/J.txt new file mode 100644 index 0000000..2e479db --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/J.txt @@ -0,0 +1 @@ +JFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/K.txt b/Priyansh Lakhotia/Python-Task 6/K.txt new file mode 100644 index 0000000..df26259 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/K.txt @@ -0,0 +1 @@ +KFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/L.txt b/Priyansh Lakhotia/Python-Task 6/L.txt new file mode 100644 index 0000000..a5b641d --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/L.txt @@ -0,0 +1 @@ +LFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/M.txt b/Priyansh Lakhotia/Python-Task 6/M.txt new file mode 100644 index 0000000..03720d9 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/M.txt @@ -0,0 +1 @@ +MFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/N.txt b/Priyansh Lakhotia/Python-Task 6/N.txt new file mode 100644 index 0000000..9392693 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/N.txt @@ -0,0 +1 @@ +NFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/O.txt b/Priyansh Lakhotia/Python-Task 6/O.txt new file mode 100644 index 0000000..c3428b8 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/O.txt @@ -0,0 +1 @@ +OFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/P.txt b/Priyansh Lakhotia/Python-Task 6/P.txt new file mode 100644 index 0000000..394863e --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/P.txt @@ -0,0 +1 @@ +PFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/Q.txt b/Priyansh Lakhotia/Python-Task 6/Q.txt new file mode 100644 index 0000000..221ba30 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/Q.txt @@ -0,0 +1 @@ +QFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/R.txt b/Priyansh Lakhotia/Python-Task 6/R.txt new file mode 100644 index 0000000..0234c15 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/R.txt @@ -0,0 +1 @@ +RFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/S.txt b/Priyansh Lakhotia/Python-Task 6/S.txt new file mode 100644 index 0000000..e7bf93b --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/S.txt @@ -0,0 +1 @@ +SFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/T.txt b/Priyansh Lakhotia/Python-Task 6/T.txt new file mode 100644 index 0000000..12d4050 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/T.txt @@ -0,0 +1 @@ +TFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/U.txt b/Priyansh Lakhotia/Python-Task 6/U.txt new file mode 100644 index 0000000..f4fc034 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/U.txt @@ -0,0 +1 @@ +UFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/V.txt b/Priyansh Lakhotia/Python-Task 6/V.txt new file mode 100644 index 0000000..36cf6ae --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/V.txt @@ -0,0 +1 @@ +VFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/W.txt b/Priyansh Lakhotia/Python-Task 6/W.txt new file mode 100644 index 0000000..87e8f40 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/W.txt @@ -0,0 +1 @@ +WFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/X.txt b/Priyansh Lakhotia/Python-Task 6/X.txt new file mode 100644 index 0000000..789fb6f --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/X.txt @@ -0,0 +1 @@ +XFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/Y.txt b/Priyansh Lakhotia/Python-Task 6/Y.txt new file mode 100644 index 0000000..a4314b3 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/Y.txt @@ -0,0 +1 @@ +YFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/Z.txt b/Priyansh Lakhotia/Python-Task 6/Z.txt new file mode 100644 index 0000000..3be6b85 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/Z.txt @@ -0,0 +1 @@ +ZFile \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/abc.txt b/Priyansh Lakhotia/Python-Task 6/abc.txt new file mode 100644 index 0000000..7f7645c --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/abc.txt @@ -0,0 +1,3 @@ +line a +line b +line c \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 6/question1.py b/Priyansh Lakhotia/Python-Task 6/question1.py new file mode 100644 index 0000000..73ca235 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/question1.py @@ -0,0 +1,15 @@ +# Question - 1 +""" +1. Write a Python program to read a file line by line and store it into a list +""" + +#Solution: + +ls=[] +f = open("abc.txt", 'r') +file_text = f.readlines() +for word in file_text: + ls.append(word) +print(ls) + + diff --git a/Priyansh Lakhotia/Python-Task 6/question2.py b/Priyansh Lakhotia/Python-Task 6/question2.py new file mode 100644 index 0000000..aeb4380 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/question2.py @@ -0,0 +1,13 @@ +# Question - 2 +""" +2. Write a Python program to read a file line by line store it into an array. +""" + +#Solution: + +arr = [] +f = open("abc.txt", 'r') +file_text = f.readlines() +for word in file_text: + arr.append(word) +print(arr) diff --git a/Priyansh Lakhotia/Python-Task 6/question3.py b/Priyansh Lakhotia/Python-Task 6/question3.py new file mode 100644 index 0000000..d2100e6 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/question3.py @@ -0,0 +1,18 @@ +# Question- 3 +""" +Write a Python program to read a random line from a file. +""" + +#Solution: + +import random +f = open("abc.txt", 'r') +h = (f.read().splitlines()) +print(random.choice(h)) + + + + + + + diff --git a/Priyansh Lakhotia/Python-Task 6/question4.py b/Priyansh Lakhotia/Python-Task 6/question4.py new file mode 100644 index 0000000..b6d9cd7 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/question4.py @@ -0,0 +1,16 @@ +# Question - 4 + +""" +4. Write a Python program to combine each line from first file with the +corresponding line in second file +""" + +#Solution: +f = open("abc.txt", 'r') +a = f.read().splitlines() +f= open("xyz.txt", 'r') +b = f.read().splitlines() +ls = [] +for i,j in zip(a,b): + print(i + j) + diff --git a/Priyansh Lakhotia/Python-Task 6/question5.py b/Priyansh Lakhotia/Python-Task 6/question5.py new file mode 100644 index 0000000..4830ff2 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/question5.py @@ -0,0 +1,19 @@ +# Question - 5 +""" +5. Write a Python program to generate 26 text files named A.txt, B.txt, and +so on up to Z.txt. +""" + +#Solution: +#For list of capital alphabets +alpha = [] +for i in range (0,26): + alpha.append(chr(ord('A') + i)) + + +#For creation of files +for word in alpha: + f= open(word + '.txt', 'w') + f.write(word + 'File') + + diff --git a/Priyansh Lakhotia/Python-Task 6/question6.py b/Priyansh Lakhotia/Python-Task 6/question6.py new file mode 100644 index 0000000..741bdfd --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/question6.py @@ -0,0 +1,14 @@ +# Question - 6 +""" +6. Write a Python program to create a file where all letters of English +alphabet are listed by specified number of letters on each line. +""" +#Solution: + +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) +letters_file_line(3) diff --git a/Priyansh Lakhotia/Python-Task 6/question7.py b/Priyansh Lakhotia/Python-Task 6/question7.py new file mode 100644 index 0000000..c681d3c --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/question7.py @@ -0,0 +1,41 @@ +# Question - 7 +""" +7. #### MAIN TASK #### + - To scrap data from worldometer example: INDIA Data and run it + on live mode. + - Print Additionally total number of Coronavirus + Cases, Deaths, Recovered. +""" + +#Solution: + +import requests #handles the http requests +from bs4 import BeautifulSoup # used to parse html data + +url = "https://www.worldometers.info/coronavirus/" +page = requests.get(url) # generating http request +print(page) # response 200 means OK + +page = page.text # to get the html code text +print(page) + +soup = BeautifulSoup(page, "html.parser") # two parameters(#data, #parse) +print(soup) #here the parsed html code is stored + +# find(div/section/head/body/h1/etc >> Tags, {class/id/xpath >> Attr : "attr_name" }) +a = soup.find("div", {"class" : "maincounter-number"}) +print(a) +print(a.text) # for only printing the text inside a + + +# printing all the text in h1 tags +b = soup.find_all("h1") +for i in b: + print(i.text) + +# for getting all three datas +c = soup.find_all("div", {"class" : "maincounter-number"}) +for i in c: + print(i.text) + + diff --git a/Priyansh Lakhotia/Python-Task 6/words1.txt b/Priyansh Lakhotia/Python-Task 6/words1.txt new file mode 100644 index 0000000..3073342 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/words1.txt @@ -0,0 +1,9 @@ +ABC +DEF +GHI +JKL +MNO +PQR +STU +VWX +YZ diff --git a/Priyansh Lakhotia/Python-Task 6/xyz.txt b/Priyansh Lakhotia/Python-Task 6/xyz.txt new file mode 100644 index 0000000..c4dfc64 --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 6/xyz.txt @@ -0,0 +1,3 @@ +line 1 +line 2 +line 3 \ No newline at end of file diff --git a/Priyansh Lakhotia/Python-Task 7/Late_night_task.py b/Priyansh Lakhotia/Python-Task 7/Late_night_task.py new file mode 100644 index 0000000..87abf3c --- /dev/null +++ b/Priyansh Lakhotia/Python-Task 7/Late_night_task.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Question : +''' +Late Night Task + +You have to Make a WhatsApp Script + +-> Till now we have seen about sending message in WhatsApp through Python using Webbrowser. + + +-> run a program and send a same message to 6 persons through a script. + + +-> Script to send "Hi" 5 times to a friend + + + + +''' +#Solution: + +import webbrowser as wb +import time +import pyautogui as g +send = False +print(time.ctime()) + +friends = ['916396326977', '919634103527', '917014310463', '917999989846', '919017135068'] + +for n in friends: + + number = int(n) + message = ("hi") + YourTime = ("00:45:00") + print(time.ctime()) + while(True): + t = time.ctime() + str(t) + a = t.split(" ") + if a[3] == YourTime: + send = True + if send == True: + print("send") + send = False + time.sleep(1) + url = 'https://wa.me/'+str(number)+'?text='+str(message) + print(url) + wb.open(url) + time.sleep(5) + g.moveTo(670, 315) + g.click() + time.sleep(5) + + g.moveTo(698, 394) # for using watsapp web + g.click() + time.sleep(10) + g.press('enter') + print("Task Complete") + break +