├── test1.py ├── REPORT.docx ├── Load and Upload Images to Sqlite3 ├── images │ ├── 1.png │ ├── 2.png │ ├── Image.db │ ├── myimage.jpg │ └── screenshot.png └── master.py ├── fetch us states name from wiki with pandas.py ├── myReg.py ├── python menu tkinter.py ├── Assingment 2a.py ├── filemenu dialog python tkinter.py ├── clean data.py ├── assingment 2c.py ├── matplot lib.py ├── google voice recognition and text to speech with python using pyaudio.py ├── assingment 2b.py ├── Assingment1a ├── assingment 1c.py ├── assingment 2f.py ├── assingment 2d.py ├── ui temperature.py ├── thingspeak Python.py ├── assingment 1b.py ├── dhtUI.py ├── assingment 1d.py ├── assingment 2e.py ├── operator overloading in python using class.py ├── Assingment 2g.py ├── volume and area of sphere and cylinder using python class.py ├── db_to_excel.py ├── FileDialog PyQT5.py └── implement Stack and Link Node using python class.py /test1.py: -------------------------------------------------------------------------------- 1 | print('hello ') 2 | 3 | -------------------------------------------------------------------------------- /REPORT.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/python-youtube-tutorials/HEAD/REPORT.docx -------------------------------------------------------------------------------- /Load and Upload Images to Sqlite3/images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/python-youtube-tutorials/HEAD/Load and Upload Images to Sqlite3/images/1.png -------------------------------------------------------------------------------- /Load and Upload Images to Sqlite3/images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/python-youtube-tutorials/HEAD/Load and Upload Images to Sqlite3/images/2.png -------------------------------------------------------------------------------- /Load and Upload Images to Sqlite3/images/Image.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/python-youtube-tutorials/HEAD/Load and Upload Images to Sqlite3/images/Image.db -------------------------------------------------------------------------------- /Load and Upload Images to Sqlite3/images/myimage.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/python-youtube-tutorials/HEAD/Load and Upload Images to Sqlite3/images/myimage.jpg -------------------------------------------------------------------------------- /Load and Upload Images to Sqlite3/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/python-youtube-tutorials/HEAD/Load and Upload Images to Sqlite3/images/screenshot.png -------------------------------------------------------------------------------- /fetch us states name from wiki with pandas.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | url=pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states') 4 | #print(url[0][1]) 5 | states=[] 6 | 7 | for x in url[0][1][1:]: 8 | states.append(x) 9 | 10 | print(states) 11 | -------------------------------------------------------------------------------- /myReg.py: -------------------------------------------------------------------------------- 1 | import docx2txt 2 | import re 3 | 4 | 5 | my_text = docx2txt.process("resume.docx") 6 | 7 | pattern = re.compile(r'[a-zA-Z0-9-\.]+@[a-zA-Z-\.]*\.(com|edu|net)') 8 | 9 | matches = pattern.finditer(my_text) 10 | 11 | for match in matches: 12 | print(match.group(0)) 13 | 14 | -------------------------------------------------------------------------------- /python menu tkinter.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | 3 | 4 | def ooo(): 5 | print("Soumil shah Youtube Channel ") 6 | 7 | mainwindow=tk.Tk() 8 | mainwindow.geometry("640x340") 9 | mainwindow.title("sensor data ") 10 | 11 | menubar=tk.Menu(mainwindow) 12 | sub_menu=tk.Menu(menubar, tearoff=0) 13 | sub_menu.add_command(label="soumil", command=ooo) 14 | sub_menu.add_separator() 15 | sub_menu.add_command(label="shah") 16 | sub_menu.add_separator() 17 | 18 | menubar.add_cascade(label="MY Name ", menu=sub_menu) 19 | 20 | mainwindow.config(menu=menubar) 21 | mainwindow.mainloop() 22 | -------------------------------------------------------------------------------- /Assingment 2a.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shah soumil Nitin 3 | Bachelor in Elecctronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | """ 8 | 9 | ''' 10 | we are asked to print the following pattern 11 | * 12 | ** 13 | *** 14 | **** 15 | ***** 16 | ''' 17 | # Take input from user how many rows we require 18 | n=int(input("Enter No of Rows to Print ")) 19 | 20 | # iterate over that number of rows 21 | for i in range(1,n+1): 22 | # iterate for stars 23 | for j in range(0,i): 24 | print(end="*") 25 | # after printing star go new line 26 | print() 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /filemenu dialog python tkinter.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import filedialog 3 | 4 | def open_handler(): 5 | name = tk.filedialog.askopenfilename(filetypes=(("file","*.jpg"),("All Files","*.*") )) 6 | print(name) 7 | 8 | mainwindow=tk.Tk() 9 | mainwindow.geometry("640x340") 10 | mainwindow.title("sensor data ") 11 | 12 | menubar=tk.Menu(mainwindow) 13 | sub_menu=tk.Menu(menubar, tearoff=0) 14 | sub_menu.add_command(label="Open File ", command=open_handler) 15 | sub_menu.add_separator() 16 | 17 | menubar.add_cascade(label="File", menu=sub_menu) 18 | 19 | mainwindow.config(menu=menubar) 20 | mainwindow.mainloop() -------------------------------------------------------------------------------- /clean data.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | data=[] 4 | clean_data=[] 5 | clean_data_1=[] 6 | 7 | 8 | try: 9 | with open('soumil.txt','r') as fname: 10 | data=fname.readlines() 11 | print(data) 12 | for x in data: 13 | print(x.strip()) 14 | val=x.strip() 15 | clean_data.append(val) 16 | clean_data_1=list(filter(''.__ne__,clean_data)) 17 | 18 | except FileNotFoundError: 19 | print("File Not Found") 20 | 21 | 22 | 23 | print(data) 24 | print(len(data)) 25 | print(clean_data) 26 | print(len(clean_data)) 27 | print(clean_data_1) 28 | print(len(clean_data_1)) 29 | 30 | -------------------------------------------------------------------------------- /assingment 2c.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shah soumil Nitin 3 | Bachelor in Elecctronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | """ 8 | 9 | ''' 10 | we are asked to print the following pattern 11 | ** 12 | **** 13 | ****** 14 | ******** 15 | 16 | ''' 17 | 18 | # take input of number of rows 19 | n=int(input("Enter Number of Rows :-")) 20 | 21 | # iterate over number of rows 22 | for i in range(1,n+1): 23 | # iterate over to print spaces 24 | for j in range(0,n-i): 25 | # print spaces 26 | print(end=" ") 27 | # iterate to print star 28 | for j in range(0,2*i): 29 | print(end="*") 30 | # end line 31 | print() 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /matplot lib.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | from matplotlib import style 3 | 4 | style.use('ggplot') 5 | 6 | x=[1,2,3,4,5] 7 | y=[1,2,3,1,2] 8 | 9 | fig=plt.figure() 10 | #ax1=plt.subplot2grid((1,1),(0,0)) 11 | 12 | 13 | ax1=fig.add_subplot(111) 14 | ax1.plot(x,y,label='Line Graph',linewidth=1,color='r') 15 | 16 | #ax2=fig.add_subplot(212) 17 | #ax2.plot(x,y,label='Line Graph',linewidth=1,color='r') 18 | 19 | 20 | 21 | ax1.grid(True,color='g',linewidth=0.2,linestyle='-') 22 | ax1.set_yticks([1,2,3,4,5]) 23 | thres=2 24 | 25 | ax1.fill_between(x,y,2,alpha=0.1,Q='g') 26 | 27 | 28 | 29 | plt.xlabel('x axis',color='r') 30 | plt.ylabel('y axis',rotation='90',color='g') 31 | plt.title('Tutorials') 32 | plt.legend() 33 | plt.show() -------------------------------------------------------------------------------- /google voice recognition and text to speech with python using pyaudio.py: -------------------------------------------------------------------------------- 1 | ''' 2 | soumil shah 3 | Bachelor in Electronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | ''' 8 | 9 | import speech_recognition as sr 10 | import pyttsx3 11 | 12 | r=sr.Recognizer() 13 | mic=sr.Microphone(device_index=1) 14 | 15 | with mic as source: 16 | audio=r.listen(source) 17 | 18 | 19 | def speak(message): 20 | engine=pyttsx3.init() 21 | rate=engine.getProperty('rate') 22 | engine.setProperty('rate',rate-10) 23 | engine.say('Google says {}'.format(message)) 24 | engine.runAndWait() 25 | 26 | 27 | print(r.recognize_google(audio))Q 28 | speak(r.recognize_google(audio)) 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /assingment 2b.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shah soumil Nitin 3 | Bachelor in Elecctronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | """ 8 | 9 | ''' 10 | we are asked to print the following pattern 11 | * 12 | ** 13 | *** 14 | **** 15 | ***** 16 | ''' 17 | # input number of rows from user 18 | n=int(input("Enter Number of Rows :")) 19 | 20 | # iterate over number of rows 21 | for i in range(1,n+1): 22 | # iterate to print spaces and decremeent space after each time 23 | for j in range(0,n-i): 24 | # print space 25 | print(end=" ") 26 | # iterate to print stars 27 | for j in range(0,i): 28 | # print stars 29 | print(end="*") 30 | # end and go to new line 31 | print() 32 | -------------------------------------------------------------------------------- /Assingment1a: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Assingment number 1 4 | 5 | Write a Python program which prompts the user for a Celsius temperature, converts the 6 | temperature to Fahrenheit, and prints out the converted temperature 7 | 8 | SOUMIL SHAH 9 | Bachelor in Electronic Engineering 10 | Master in Electrical Engineering 11 | Master in Computer Engineering 12 | 13 | 14 | """ 15 | 16 | def temperature(): 17 | formula= 0 18 | # Take input from user 19 | cel = input("Enter Temperature in Celsius ! ") 20 | # convert string into float 21 | 22 | cel=float(cel) 23 | # do the calculation for converting temperature 24 | fahrenheit= cel * (9/5) + 32 25 | 26 | print("Temperature in Fahrenheit {} ".format(fahrenheit)) 27 | 28 | return fahrenheit 29 | 30 | while True: 31 | temperature() 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /assingment 1c.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Assingment number 1 4 | 5 | I have started walking to home at 7:30 AM for the first mile at slow step (8 min:15 sec 6 | per mile), then 3 miles at speed (7 min:12 sec per mile), what time do I get home for 7 | breakfast? (format output in hh: min) 8 | 9 | SOUMIL SHAH 10 | Bachelor in Electronic Engineering 11 | Master in Electrical Engineering 12 | Master in Computer Engineering 13 | 14 | 15 | """ 16 | 17 | import datetime 18 | 19 | walk = datetime.datetime(2018, 8, 1,7, 30, 00) 20 | 21 | # 1 mile 8 MIN 15 SEC 22 | walk_1 = walk + datetime.timedelta(0,minutes=8,seconds=15) 23 | 24 | # 3 mile it takes 7 Min 12 sec per Mile 25 | # 2 nd mile calculate 26 | walk_2 = walk_1 + datetime.timedelta(0,minutes= 7, seconds= 12) 27 | 28 | # walk 3 mile 29 | walk_3 = walk_2 + datetime.timedelta(0, minutes=7, seconds=12) 30 | 31 | # last Mile 32 | walk_4 = walk_3 + datetime.timedelta(0, minutes=7, seconds=12) 33 | 34 | print("You Will reach for BreakFast at {} ".format(walk_4)) -------------------------------------------------------------------------------- /assingment 2f.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shah soumil Nitin 3 | Bachelor in Elecctronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | """ 8 | 9 | # Define function to return true or false if its leap year 10 | 11 | ''' 12 | There are three criteria to identify leap years: 13 | The year can be evenly divided by 4, is a leap year, unless: 14 | The year can be evenly divided by 100, it is NOT a leap year, unless: 15 | The year is also evenly divisible by 400. Then it is a leap year. 16 | This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years. 17 | ''' 18 | 19 | 20 | def leayr(n): 21 | if n % 400 == 0: 22 | return True 23 | if n % 100 == 0: 24 | return False 25 | if n % 4 == 0: 26 | return True 27 | else: 28 | return False 29 | 30 | 31 | value = int(input("Enter Year to check if its a leap year or not ")) 32 | # return value 33 | reply=leayr(value) 34 | 35 | if reply== True: 36 | print ("{} is a leap year".format(value)) 37 | else: 38 | print("{} is not a leap Year".format(value)) 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /assingment 2d.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shah soumil Nitin 3 | Bachelor in Elecctronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | """ 8 | # Define Function to return morse code 9 | 10 | def morse_code(n): 11 | # store morse code in keys 12 | keys=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.", 13 | "---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] 14 | # store alphabet in a list 15 | alphabet= ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] 16 | # make a dictionary with alphabet as key and keys as value 17 | dictionary= dict(zip(alphabet,keys)) 18 | #return the required morse code from dict using get function 19 | return dictionary.get(n) 20 | 21 | # take input from user 22 | answer=input("ENTER Word") 23 | #store input in list 24 | answer=list(answer) 25 | 26 | word="" 27 | # iterate over list to extract individual elements using for loop 28 | for x in answer: 29 | # call function for that req string 30 | # join the string 31 | word = word + morse_code(x) 32 | 33 | print(word) -------------------------------------------------------------------------------- /ui temperature.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | import numpy as np 3 | import random 4 | import time 5 | import datetime 6 | import threading 7 | 8 | 9 | def tick(): 10 | 11 | time2=time.strftime('%H:%M:%S') 12 | clock.config(text=time2) 13 | clock.after(200,tick) 14 | 15 | 16 | def get_data(): 17 | threading.Timer(5, get_data).start() 18 | x=np.random.randint(0,40,1) 19 | print(x[0]) 20 | l_display.config(text = x[0]) 21 | return x[0] 22 | 23 | mainwindow = tk.Tk() 24 | mainwindow.geometry('640x340') 25 | mainwindow.title("Sensor Data Live Feed ") 26 | 27 | clock=tk.Label(mainwindow,font=("Arial",30), bg='green',fg="white") 28 | clock.grid(row=0, column=0, padx=10, pady=10, sticky="nsew") 29 | 30 | l_m=tk.Label(mainwindow,text="Sensor Data ",font=("Arial",30),fg="Black") 31 | l_m.grid(row=0,column=1, padx=10, pady=10, sticky="nsew") 32 | 33 | l_t=tk.Label(mainwindow, text="Temperature C",font=("Arial",25)) 34 | l_t.grid(row=1,column=0, padx=10, pady=10, sticky="nsew") 35 | 36 | l_display=tk.Label(mainwindow,font=("Arial",25),fg="red") 37 | l_display.grid(row=1,column=1, padx=10, pady=10, sticky="nsew") 38 | 39 | 40 | tick() 41 | get_data() 42 | 43 | mainwindow.mainloop() 44 | 45 | -------------------------------------------------------------------------------- /thingspeak Python.py: -------------------------------------------------------------------------------- 1 | import urllib.request 2 | import requests 3 | import threading 4 | import json 5 | 6 | import random 7 | 8 | 9 | # Define a function that will post on server every 15 Seconds 10 | 11 | def thingspeak_post(): 12 | threading.Timer(15,thingspeak_post).start() 13 | val=random.randint(1,30) 14 | URl='https://api.thingspeak.com/update?api_key=' 15 | KEY='WRITE KEY XXXXXXXXXXX ' 16 | HEADER='&field1={}&field2={}'.format(val,val) 17 | NEW_URL=URl+KEY+HEADER 18 | print(NEW_URL) 19 | data=urllib.request.urlopen(NEW_URL) 20 | print(data) 21 | 22 | def read_data_thingspeak(): 23 | URL='https://api.thingspeak.com/channels/557500/fields/1.json?api_key=' 24 | KEY='READ KEY XXXXX ' 25 | HEADER='&results=2' 26 | NEW_URL=URL+KEY+HEADER 27 | print(NEW_URL) 28 | 29 | get_data=requests.get(NEW_URL).json() 30 | #print(get_data) 31 | channel_id=get_data['channel']['id'] 32 | 33 | feild_1=get_data['feeds'] 34 | #print(feild_1) 35 | 36 | t=[] 37 | for x in feild_1: 38 | #print(x['field1']) 39 | t.append(x['field1']) 40 | 41 | if __name__ == '__main__': 42 | #thingspeak_post() 43 | read_data_thingspeak() 44 | 45 | 46 | -------------------------------------------------------------------------------- /assingment 1b.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Assingment number 1 4 | 5 | The cover price of a book is $25, but bookstores get a 10% discount. Shipping costs $2 6 | for the first five copies and 2.75 cents for all rest of copies. Write a Python program to 7 | show what is the total wholesale cost for 40 copies display the result. 8 | 9 | SOUMIL SHAH 10 | Bachelor in Electronic Engineering 11 | Master in Electrical Engineering 12 | Master in Computer Engineering 13 | 14 | 15 | """ 16 | # Declare all the values mentioned in problem 17 | 18 | total_book= 40 19 | cost_price = 25 20 | discount = 10/100 21 | shipping_5 = 2 22 | shipping_rest_35 = 2.75 23 | 24 | # cost of book withouth Discount 25 | Book_cost_no_discount = 40 * 25 26 | 27 | # Cost of book with Discount 28 | book_cost_discount = Book_cost_no_discount - (discount * Book_cost_no_discount) 29 | 30 | # Calculate shipping cost of 5 books 31 | shipping_5_book= 2 * 5 32 | 33 | # Calculate shipping cost of rest of books 34 | shipping_35_book = shipping_rest_35 * 35 35 | 36 | # calculate maths for all book 37 | wholesale_cost= book_cost_discount + shipping_5_book + shipping_35_book 38 | 39 | # print Result 40 | print("Whole Sale Cost of 40 Books is $ {} ".format(wholesale_cost)) 41 | 42 | 43 | -------------------------------------------------------------------------------- /dhtUI.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | import numpy as np 3 | import random 4 | import time 5 | import datetime 6 | import threading 7 | import Adafruit_DHT 8 | 9 | pin = 4 10 | sensor = Adafruit_DHT.DHT22 11 | 12 | def tick(): 13 | 14 | time2=time.strftime('%H:%M:%S') 15 | clock.config(text=time2) 16 | clock.after(200,tick) 17 | 18 | 19 | def get_data(): 20 | 21 | threading.Timer(5, get_data).start() 22 | 23 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 24 | 25 | if humidity is not None and temperature is not None: 26 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) 27 | l_display.config(text = temperature) 28 | else: 29 | print('Failed to get reading. Try again!') 30 | 31 | 32 | return temperature 33 | 34 | 35 | 36 | mainwindow = tk.Tk() 37 | mainwindow.geometry('640x340') 38 | mainwindow.title("Sensor Data Live Feed ") 39 | 40 | clock=tk.Label(mainwindow,font=("Arial",30), bg='green',fg="white") 41 | clock.grid(row=0, column=0, padx=10, pady=10, sticky="nsew") 42 | 43 | l_m=tk.Label(mainwindow,text="Sensor Data ",font=("Arial",30),fg="Black") 44 | l_m.grid(row=0,column=1, padx=10, pady=10, sticky="nsew") 45 | 46 | l_t=tk.Label(mainwindow, text="Temperature C",font=("Arial",25)) 47 | l_t.grid(row=1,column=0, padx=10, pady=10, sticky="nsew") 48 | 49 | l_display=tk.Label(mainwindow,font=("Arial",25),fg="red") 50 | l_display.grid(row=1,column=1, padx=10, pady=10, sticky="nsew") 51 | 52 | 53 | tick() 54 | get_data() 55 | 56 | mainwindow.mainloop() 57 | 58 | -------------------------------------------------------------------------------- /assingment 1d.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Assingment number 1 4 | 5 | Write a Python code to calculate the speed for running a 10-kilometer race in 1 hours 5 6 | minutes 42 seconds. What is the average pace (time per mile in minutes and seconds)? 7 | What is the average speed in miles per hour? 8 | 9 | SOUMIL SHAH 10 | Bachelor in Electronic Engineering 11 | Master in Electrical Engineering 12 | Master in Computer Engineering 13 | 14 | 15 | """ 16 | import datetime 17 | 18 | # Distance in Km 19 | distance= 10 20 | 21 | # Distance in Mile 22 | distance_mile_10= 6.213 23 | 24 | time= datetime.datetime(2018,9,1,1,5,42) 25 | 26 | # extract minutes and seconds 27 | minute=time.minute 28 | sec=time.second 29 | 30 | # convert minutes in hours 31 | minute_5_to_hour= 0.0166667 * 5 32 | sec_42__to_hour= 0.00027777833333 * 42 33 | hour=time.hour 34 | 35 | total_hour = hour + minute_5_to_hour + sec_42__to_hour 36 | speed_km_hr = distance / total_hour 37 | 38 | # convert km/hr into mile/hr 39 | speed_mile = 0.621371 * speed_km_hr 40 | 41 | #calculate total mile/minute 42 | total_minute= 60 + 5 + 0.0166667 43 | speed_mile_minute= distance_mile_10 / total_minute 44 | 45 | #calculate speed in mile/sec 46 | total_sec= 3600 + 300 + 42 47 | speed_mile_sec= distance_mile_10 / total_sec 48 | 49 | 50 | print("Complete Race of 10 KM in 1:5:42 speed has to be {} km/hr ".format(speed_km_hr)) 51 | print("Complete Race of 10 KM in 1:5:42 speed has to be {} Mile/hr ".format(speed_mile)) 52 | print("Complete Race of 10 KM in 1:5:42 speed has to be {} Mile/Min ".format(speed_mile_minute)) 53 | print("Complete Race of 10 KM in 1:5:42 speed has to be {} Mile/sec ".format(speed_mile_sec)) -------------------------------------------------------------------------------- /assingment 2e.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shah soumil Nitin 3 | Bachelor in Elecctronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | """ 8 | # Define intital text to display on screen 9 | text= """ 10 | ---------------------------- 11 | Welcome to Robot Software 12 | Please Enter 13 | l/L for left 14 | r/R fro Right 15 | u/U for up 16 | d/D for down 17 | Enter your Input below 18 | ----------------------------- 19 | """ 20 | 21 | # Define the function for robot 22 | 23 | def is_round(i): 24 | x=0 25 | y=0 26 | # set inital position as 0,0 27 | # whatever strig user enter break it and fetch line by line to software 28 | 29 | for i in i: 30 | # check for r if yes inc x 31 | 32 | if i == "r": 33 | x=x+1 34 | # check for l if yes dec x 35 | if i == "l": 36 | x=x-1 37 | # check for u if yes inc y 38 | if i == "u": 39 | y=y+1 40 | # check for u if yes dec y 41 | if i == "d": 42 | y=y-1 43 | # return the value of x and y check if its back and return True or False 44 | return x==0 and y==0 45 | 46 | # Take input from userp and convert into lower 47 | user=input(text).lower() 48 | # pass input to function and return true or false 49 | path = is_round(user) 50 | print(path) 51 | # check condition if its at start or made circle 52 | if path == True: 53 | print("You Are back at initial position") 54 | print("True") 55 | else: 56 | print("You are not back at same position from where you have started ") 57 | print("False") 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /operator overloading in python using class.py: -------------------------------------------------------------------------------- 1 | from operator import add # import all library 2 | 3 | class Compute: # Define a class 4 | 5 | def __init__(self,data): # Define a constructor 6 | self.data =data 7 | 8 | def __add__(self, other): # define a method overloading 9 | 10 | # check data for int 11 | 12 | if isinstance(self.data,list) and isinstance(other.data,list): 13 | return list(map(add,self.data,other.data)) 14 | 15 | # check data for tuple 16 | 17 | elif isinstance(self.data,tuple) and isinstance(other.data,tuple): 18 | return tuple(map(add,self.data,other.data)) 19 | 20 | # Check for Dict 21 | 22 | elif isinstance(self.data,dict) and isinstance(other.data,dict): 23 | dict1 = self.data 24 | dict2 = other.data 25 | for k in dict2: 26 | if k in dict1: 27 | dict1[k] += dict2[k] 28 | else: 29 | dict1[k] = dict2[k] 30 | return dict1 31 | else: 32 | print('Given data is not List,Tuple, Dictionary or input have different dataTypes ') 33 | 34 | def main(): # Define main 35 | c1 = Compute([1,2,3,4]) 36 | c2 = Compute([3.3,4,5,1.2]) 37 | print(c1+c2) 38 | 39 | c3 = Compute({1:'abc',3:'xyz',5:'test'}) 40 | c4 = Compute({2:'test1',3:'test2',4:'test3'}) 41 | print(c3+c4) 42 | 43 | 44 | if __name__ == '__main__': 45 | main() 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Assingment 2g.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shah soumil Nitin 3 | Bachelor in Elecctronic Engineering 4 | Master in Electrical Engineering 5 | Master in Computer Engineering 6 | 7 | """ 8 | 9 | text=""" 10 | Welcome to 2's compliment software 11 | please Enter Decimal number 12 | example:- 4 13 | 14 | """ 15 | 16 | 17 | 18 | def findComplement(num): 19 | 20 | numWord=bin(num) #converts decimal number to binary representation 21 | numWord=numWord[2:] #trims initial 2 chars from the string 22 | length=len(numWord) #calculates the length of the string 23 | i=0 24 | res='' 25 | #Following loop would iterate for every char to convert it. 26 | 27 | while i