Skip to content

Big Data Submission 1st #2

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

Open
wants to merge 6 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
32 changes: 32 additions & 0 deletions Python Assignment 1/Python Class 1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Ques 1: What is JPython & CPython?
Ans: JPython: Jython is the JVM implementation of the Python programming language.
It is designed to run on the Java platform.
A Jython program can import and use any Java class.
Just as Java, Jython program compiles to bytecode.
One of the main advantages is that a user interface designed in Python can use GUI elements of AWT, Swing or SWT Package.
Jython, which started as JPython and was later renamed, follows closely the standard Python implementation called CPython as created by Guido Van Rossum.
CPython: CPython is the reference implementation of the Python programming language.
Written in C and Python, CPython is the default and most widely used implementation of the language.
CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before interpreting it.
It has a foreign function interface with several languages including C, in which one must explicitly write bindings in a language other than Python.

Ques 2: Basic difference between Python2 and Python3?
Ans: Basis of comparison Python 3 Python 2
Release Date 2008 2000
Function print print ("hello") print "hello"
Syntax simpler comparatively difficult to understand
Iteration Range() func. xrange() is used for iterations.

Ques 3: Difference between ASCII and Unicode?
Ans: ASCII: It stands for American Standart Code for Information Interchange. It uses 8-bit encoding.
ASCII represents 128 characters.
It is stored as 8-bit byte.
ASCII is not standardized.

Unicode: It is also a character encoding but uses variable bit encoding.
Unicode defones 2^21 characters. Unicode is a superset of ASCII. It represents more characters than ASCII.
Unicode is stored in byte sequences such as UTF-32 and UTF-8.
Unicode is standardized.



26 changes: 26 additions & 0 deletions Python Assignment 1/Python Class 2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Ques: What should be the output of the following?
(3+4**6-9*10/2)
Ans: 4054.0

Ques: Let say I have, some string "hello this side regex". Find out the count of the total vowels in this string.
Ans: >>>vowels='a,e,i,o,u'
>>>vowels
>>>count=0
>>>string='hello this side regex'
>>>for s in string:
if s in vowels: count=count+1
>>>count

Ques: Find out the area of triangle. You have to take value from user about the base, and the height.
Ans: >>> b = float(input('Enter base of a triangle: '))
>>> h = float(input('Enter height of a triangle: '))
>>> area = (b * h) / 2
>>> print('The area of the triangle is %0.1f' % area)

Ques: Print the calender on the terminal. If you give the year.
-allow the user to input the year.
-then print that calender of that year.
Ans: import calendar
y = int(input("Input the year : "))
m = int(input("Input the month : "))
print(calendar.month(y, m))
34 changes: 34 additions & 0 deletions Python Assignment 2/Assignment 1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Ques 1: Find the Armstrong number between the two numbers which are input by user
Armstrong numbers: 153-> 1*1*1 + 5*5*5 + 3*3*3
Ans 1: x, y = input("Enter two values value: ").split()
x=int(x)
y= int(y)
for num in range(x,y,1) :
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")

Ques 2: 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 2: s='hello this world @2020!!! '
s=list(s)
punc=['@','!','#','$','%','&','*','(',')']
a=[]
for i in s:
if i in punc:
continue
else:
a.append(i)''.join(str(i) for i in a)

Ques 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?
Ans 3: li =['Apple', 'banana', 'cat', 'REGEX','apple']
li.sort(key=str.casefold)
li[0:3]
98 changes: 98 additions & 0 deletions Python Assignment 2/Assignment 2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Ques 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"]
Ans 1: List = []
List= ["GOA","RAJASTHAN","KARNATAKA","GUJRAT","MANIPUR","MADHYA PRADESH"]
for i in List:
print(i[0])
s= list(List)
print(s)

Ques 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' ]
Ans 2: LIST= ['GAnga', 'Tapti', 'Kaveri', 'Yamuna', 'Narmada' ]
LIST
k=0
for i in LIST:
j=0
sum=0
for j in i:
sum=sum + ord(j)
LIST[k]=sum
k+=1
print(LIST)

Ques 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 help of If/Else statement
Ans 3: import time
while True:
x= time.ctime()
ls= x.split(" ")
print(ls)
if ls== ['Wed', 'Apr', '15', '14:30:03', '2020']:
print("This is the time!!")
break
else:
continue

Ques 4: 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.
Ans 4: 1. print(tuple[0:])
2. #tuples are immutable, so you can not remove elements
#using merge of tuples with the + operator you can remove an item and it will create a new tuple

tuple = tuple[:3] + tuple[4:]

Ques 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 which are less then 10 or equal to 10
- store the above two lists in two different list.
Ans 5: l1=[]
l2=[]
for i in REGex:
if i > 20:
print(i)
l1.append(i)
if i <= 10:
print(i)
l2.append(i)

print(l1)
print(l2)

Ques 6: Execute standard LINUX Commands using Python Programming.
Ans 6: import os
cmd = 'wc -l my_text_file.txt > out_file.txt'
os.system(cmd)

Ques 7: Revise *args and **kwargs Concepts.
Ans 7: *args (Non Keyword Arguments)
**kwargs (Keyword Arguments)
We use *args and **kwargs as an argument when we are unsure about the number of arguments to pass in the functions.
i.) *args:
def adder(*num):
sum = 0

for n in num:
sum = sum + n

print("Sum:",sum)

adder(3,5)
adder(4,5,6,7)
adder(1,2,3,5,6)

ii.) **kwargs:
def intro(**data):
print("\nData type of argument:",type(data))

for key, value in data.items():
print("{} is {}".format(key,value))

intro(Firstname="Sita", Lastname="Sharma", Age=22, Phone=1234567890)
intro(Firstname="John", Lastname="Wood", Email="[email protected]", Country="Wakanda", Age=25, Phone=9876543210)
58 changes: 58 additions & 0 deletions Python Assignment 2/Assignment 3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Ques 1: Make a use of time module and for loop and create Loading..... animation 5 times. Note: you have to print only Loading.... in the animated form.
Ans 1: import time as t
import sys
sys.stdout.write('Loading')
for i in range(5):
sys.stdout.write('.')
t.sleep(1)

Ques 2: Difference between Return and Yield ?
Ans 2: Return: Returns the value to the caller
Return statement runs only one time
Return statement causes a function to exit.
Code written after return statement won't execute
Every function calls run the function from the start.

Yield: Yield returns the value to the caller and also preserve the current state
Yield statement can run multiple times.
Yield statement is used to define the generators.
Code written after yield statement execute in next function call.
Yield statement function is executed from the last state from where the function get paused.

Ques 3: Make digital clock and run it for 5 sec.
Ans 3: import time as t
for i in range(5):
a=str(t.ctime())
b=a.split(" ")
print(b[3])
t.sleep(1)

Ques 4: Adding anything in tuple eg:(1,2,3,4) -> (1,2,3,4,5)
Ans 4: old=(1,2,3,4)
lists=list(old)
print(type(lists))
x=input("Enter value: ")
lists.append(x)
new=tuple(lists)
print(new,type(new))

Ques 5: Whatsapp texting using web browser library.
Ans 5: import webbrowser as wb
import time
import datetime
number= input("Please enter the whatsapp number of the person you want to send message to:")
message= input("Enter the message you want to send:")
t= input("Enter the time (hh:mm:ss):")
while True:
c_time= time.ctime()
t_format= c_time[10:18]
time.sleep(1)
print(f'c_time : {t_format}')
if t==t_format :
webbrowser.open_new_tab(f'https://web.whatsapp.com/send?phone=+91{number} and text={message}')
break
elif t<t_format :
print("Please enter the correct time!")
break
else :
print("Please wait for a second...")
64 changes: 64 additions & 0 deletions Python Assignment 2/Assignment 4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Ques 1: Write a Python program to read a file line by line and store it into a list.
Ans 1: def read_file(filename):
with open(filename) as f:
content_list = f.readlines()
print(content_list)

read_file('Assignment 4.txt')

Ques 2: Write a Python program to read a file line by line and store it into an array.
Ans 2: def file_read(filename):
content_array = []
with open(filename) as f:
for line in f:
content_array.append(line)
print(content_array)

file_read('Assignment 4.txt')

Ques 3: Write a python program to read a random line from a file.
Ans 3: import random
def random_line(filename):
lines = open(filename).read().splitlines()
return random.choice(lines)
print(random_line('Assignment 4.txt'))

Ques 4: Write a python program to combine each line from first file with the corresponding line in the second file.
Ans 4: with open('Asignment 3.txt') as f1, open('Assignment 4.txt') as f2:
for line1, line2 in zip(f1, f2):
print(line1+line2)

Ques 5: Write a python program to generate 26 text files named A.txt, B.txt, and so on uo to Z.txt.
Ans 5: import os, string
if not os.path.exists("letters"):
os.makedirs("letters")
for letter in string.ascii_uppercase:
with open(letter + ".txt", "w") as f:
f.writelines(letter)

Ques 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.
Ans 6: import string
def letters_file_line(n):
with open("words.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)

Ques 7: ##MAIN TASK##
- To scrap data from worldometer example: INDIA Data and run it on live mode.
- Print additionally total no. of Coronavirus Cases, Deaths, Recovered.
Ans 7: import requests
from bs4 import BeautifulSoup
import time
while True:
url = "https://www.worldometers.info/coronavirus/country/india/"
time.sleep(10)
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
b = soup.findAll('h1')
c = soup.findAll('div',{'class':'maincounter-number'})
list_b=[i.text for i in b]
list_c=[j.text for j in c]
for i,j in zip(list_b[1:],list_c):
print(i+j)
13 changes: 13 additions & 0 deletions Python Assignment 2/Assignment 5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Ques: Construct a World Meter Corona Cases table.
Ans: import requests
from bs4 import BeautifulSoup
url = "https://www.worldometers.info/coronavirus/"
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
data=soup.find("table", {"id":"main_table_countries_today"})
a=str(data.text.strip()).replace(","," ")
a=a.replace("\n",",").replace(",,"," ")
print(a)
f=open("world_data.txt",'a')
f.write(a)
f.close()
Loading