Posts

Showing posts with the label modules

Plotting Graphs in Python with Matplotlib Library

import matplotlib.pyplot as plt # one line graph plotting x = [1,2,3,4,5] y = [320, 400, 650, 456, 870] plt.plot(x,y) # customizing your graph # plt.plot( # x, y, color="red", linestyle="dashed", # linewidth=2, marker="o", markerfacecolor="cyan", # markersize=14 # ) # plt.xlim(1,10) # x axis limits # plt.ylim(1,1000) # y axis limits plt.xlabel("Months") plt.ylabel("Gas Bills") plt.title("Gas bills of the months") plt.show() ############################################ # two-lines graph plotting x1 = [1,2,3,4,5] y1 = [320, 400, 650, 456, 870] plt.plot(x1,y1, label="Gas Bills") x2 = [1,2,3,4,5] y2 = [620, 800, 450, 556, 270] plt.plot(x2,y2, label="Water Bills") plt.xlabel("Months") plt.ylabel("Billing Amount") plt.title("Bills of the months") plt.legend() plt.show() ############################################ # creating a bar chart player

Greetings Program in Python

Just enter your name and the program will greet you according to the time of the day. Note: If you run this program on your computer, it will respond according to your system time. In case you run this program on any online platform, it may respond according to the server time on which that platform is hosted. import time name = input("Plz enter your name: ") # timeNow = time.strftime("%H:%M:%S") # print(timeNow) hr = int(time.strftime("%H")) # print(hr) mints = int(time.strftime("%M")) # print(mints) secs = int(time.strftime("%S")) # print(secs) if hr in range(6, 12): if mints in range(0, 60): if secs in range(0, 60): print("Good Morning", name) elif hr in range(12, 14): if mints in range(0, 60): if secs in range(0, 60): print("Good Noon", name) elif hr in range(14, 17): if mints in range(0, 60): if secs in range(0, 60):

Pickle Module in Python

import pickle # pickling a python object mylist = ["waqas", "sheeraz",{"sheeraz": "haroon", "sheer": "veer"}, "haroon", "farrukh"] file_object = open("mylist.pkl", "wb") # write as binary file pickle.dump(file=file_object, obj=mylist) file_object.close() # unpickling into python object fileb = open("mylist.pkl", "rb") # read binary file python_obj = pickle.load(file=fileb) print(python_obj) fileb.close()

Text to Speech conversion in Python

from win32com.client import Dispatch speak_it = Dispatch("SAPI.SpVoice") string = input("Enter the text and we will speak it: ") speak_it.Speak(string)