• Python

    Best Way to Learn Python (2021 Step-by-Step Guide)

    Python is a very popular language. It’s also one of the languages that I recommend for beginners to start with. But how do you go about learning this language? The best way to learn Python is to understand the big picture of all what you need to learn before you dive in and start learning. In this article, I divide the path of learning Python into 6 levels. Each level covers a subset of the language that you need to master before you move on to the next one. My focus on this article is for you to be a competent well-rounded programmer so you…

  • Python

    Consider the following formula and evaluate the y value for the range of t values found in a file with format 𝑦(𝑡)=𝑣0𝑡−0.5𝑔𝑡2

    Problem: Consider the following formula and evaluate the y value for the range of t values found in a file with format 𝑦(𝑡)=𝑣0𝑡−0.5𝑔𝑡2 File Format: v0 3.0 t: 0.15592 0.28075 0.36807889 0.35 0.57681501876 0.21342619 0.0519085 0.042 0.27 0.50620017 0.528 0.2094294 0.1117 0.53012 0.3729850 0.39325246 0.21385894 0.3464815 0.57982969 0.10262264 0.29584013 0.17383923 More precisely, the first two lines are always present, while the next lines contain an arbitrary number of t values on each line, separated by one or more spaces. i. Write a function that reads the input file and returns v0 and a list with the t values. ii. Write…

  • Python

    Read data from two file and calculate salary of employee

    Problem: An organization wants to compute monthly wages to be paid to an employee in an organization. The input data is provided in two different files. File1 contains permanent employee data about employees (i.e. Empid, name, hourly wages), and File2 contains working hours information of each employee in the current month (i.e., empid and hours). Individual elements of data are separated by commas. Design a python program that reads both the files, computes the monthly wages of each employee and store in another file. Take both file names as command line arguments and check the respected exceptions for the same.…

  • Python

    Check Whether The Number Is Prime Or Not

    Write a function that takes two numbers as input parameters and returns True or False depending on whether they are co-primes. Two numbers are said to be co-prime if they do not have any common divisor other than one. flag=0 def coprime(no1,no2): global flag mini=no1 if no1<no2 else no2 i=2 while i<mini: if no1%i==0 and no2%i==0: flag=1 break i+=1 no1=int(input("Enter First Number ")) no2=int(input("Enter Second Number ")) coprime(no1,no2) if flag==1: print("Numbers Are Not Co-Prime") else: print("Numbers Are Co-Prime") OutPut Enter First Number 25 Enter Second Number 50 Numbers Are Not Co-Prime  

  • Python

    Count Word, Line, Words Start From Vowel From File Python

    Write a python program that reads the contents of the file poem.txt and count the number of alphabets blank spaces lowercase letters and uppercase letters the number of words starting from vowel and the number of occurrences of each word in the file. alphabet=0 space=0 lower=0 upper=0 voword=0 oc=0 occur={} f=open("data.txt","r") content=f.read() vowel=['a','e','i','o','u','A','E','I',"O",'U'] print("Contet Of File") print(content) print("\nTotal Length Of File",len(content)) words=content.split(' ') #print(words) for i in range(len(content)): #print(content[i]) if (content[i]>='a' and content[i]<='z') or (content[i]>='A' and content[i]<='Z'): lower+=1 alphabet+=1 if content[i]>='A' and content[i]<='Z': upper+=1 if(content[i]==' '): space+=1 for i in range(len(words)): str=words[i] oc=0 if str[0] in vowel: voword+=1 for j…

  • Python

    Recursive Function In Python

    Write a recursive function that takes x value as an input parameter and print x-digit strictly in increasing number. [i.e. x = 6 than output 67891011]. def printdemo(x,count): if(count<=0): return else: print(x,end='') x=x+1 count=count-1 printdemo(x,count) x=int(input("Enter Number ")) printdemo(x,x) OutPut Enter Number 7 78910111213  

  • Python

    Convert Digit Into Word

    This program will convert from number to word. For this purpose we are using dictionary data type which is used with key value pairs. Here the main logic is put into function which is defined by following Syntex. def fun_name(argument): def maptoword(number): global list list=[] dic={0:'ZERO',1:'ONE',2:'TWO',3:'THREE',4:'FOUR',5:'FIVE',6:'SIX',7:'SEVEN',8:'EIGHT',9:'NINE'} temp=number while temp!=0: rem=temp%10 list.append(dic[rem]) temp=int(temp/10) i=len(list) i=i-1 while i>=0: print(list.pop(i),end=' ') i=i-1 number=int(input("Enter any number")) maptoword(number)   OutPut Enter any number123 ONE TWO THREE

  • Python

    Implement The Basic Calculator

    Here we are using basic operator and function to implement basic calculator. This program provide basic use of operator and how to work with function. con=1 while con==1: no1=int(input("Enter First Value ")) no2=int(input("Enter Second Value ")) print("Choice") print("1. Add") print("2. Subtract") print("3. Multiplication") print("4. Division") choice=int(input("Enter Choice ")) def Add(): return (no1+no2) def Sub(): return (no1-no2) def Mul(): return (no1*no2) def Div(): return (no1/no2) def perform_op(choice): if choice == 1: print(Add()) elif choice == 2: print(Sub()) elif choice == 3: print(Mul()) elif choice == 4: print(Div()) else: print("*** Invalid Choice ***") perform_op(choice) con=int(input("Do You Want To Continue "))   OutPut…

  • Python

    Implement The Gaussian Function

    The bell shaped Gaussian function, f(x)=(1/s * root(2*pi)) * exp[(-1/2) * (x-m/s)^2] is one of the most widely used functions in science and technology. The parameters m and s > 0 are prescribed real numbers. Make a program for evaluating this function for different values of s, x and m. Ask the user to input the values import math s=float(input("Enter the value of s ")) x=float(input("Enter the value of x ")) m=float(input("Enter the value of m ")) if(m<0 and s<0): print("** Invalid Input **") else: f1=1/(s*math.sqrt((2*3.14))) f2=math.exp((-1/2)*(pow(((x-m)/s),2))) f=f1*f2 print("Answer ",f) OutPut Enter the value of s 3 Enter the value…