An awesome README template to jumpstart your projects!
Explore the MDN docs »
Table of Contents
I have added some programs on the basic concepts of Python for starters. The concepts are regarding Functions, conditional statements, iterations, strings, lists, tuples and dictionaries etc.
In this program, conditional if-else, elif statements are used to produce grades on numbers given by the user.
In the first step, five numbers of floating number datatype in respective subjects are input by the user and stored in five variables.
Then, the numbers are added and stored in a variable sum. Afterwards sum is divided by the total number of subjects i.e, 5 to get the average.
After getting the average in a variable avg, if-else elif condition is used to compare the avg in order to assign grade.
The grades, according to the average marks are A,B,C,D,E and F.
if the average is higher than or equal to 90 and smaller than 100, then it will print grade A.
if the average is higher than or equal to 80 and smaller than 90, then it will print grade B.
if the average is higher than or equal to 70 and smaller than 80, then it will print grade C.
if the average is higher than or equal to 60 and smaller than 70, then it will print grade D.
if the average is higher than or equal to 50 and smaller than 60, then it will print grade E.
if the average is higher than or equal to 0 and smaller than 50, then it will print grade F.
if the average marks are not between 0 to 100, then the else option will be printed, which will give a warning that the numbers entered are wrong.
In this program, while-loop is used to repeatedly run the program in a neverending sequence.
In the first step, two variables are initialized with the value 1 and 2 and a while condition is applied that will run the program for an unlimited period.
The balance is taken as input from the user as floating point number and stored in a variable balance.
A condition is given to the user to enter 1 or 2 for Withdrawal or Depositing.
If the user types 1, then a certain amount, to be input by the user, would be withdrawed from the balance entered previously.
If the user types 2, then a certain amount, to be input by the user, would be deposited into the balance entered previously.
In this program, two matrices of same order are created by input from the user and these matrices are added together to form another matrix.
In the first step, a function matrix1() is defined with m,n as perimeteres. then by using the append function in a for loop, the input values are added in the list on that specific position.
The elements of the list are printed in position through another for loop to form a matrix.
The function is then called with 5,3 as perimeter.
Another function matrix2() is defined with a,b as perimeteres. then by using the append function in a for loop, the input values are added in the list on that specific position.
The elements of the list are printed in position through another for loop to form a matrix.
The function is then called with 5,3 as perimeter for the order to remain the same.
Now using the append function in for loop again, the elements of the matrices in alike positions are added to form a list.
The list is then again printed in a sequence to form a matrix through the for loop.
In this program, a list is made by user input and the Maximum,Minimum,Sum and Average of the list are to be find.
In the first step, a list is made by iterating an append function by user input in a for loop.
Two functions, myMax() and myMin() are defined to find Maximum and Minimum number in the list.
Then these functions are called to be printed.
Sum of the list is found through iterating the list in for loop and then the average is calculated and printed.
In this program two tuples are made by user input and are compared. Then the Maximum and Minimum of both tuples are found. Also elements are added in the original tuples to create new ones.
A function tup() is defined in order to create tuples.
In the function, a list is created by user input using append function in a for loop, then the list is converted to tuple.
Both tuples are created using this function tup().
Then the tuples are compared by if-else condition.
In the next step, minimum and maximum of both tuples are printed using built-in functions min() and max().
At the end both tuples undergo addition of elements and new tuples are created and printed.
This program is designed to count the number of times a certain word appears in a file:'filen.txt'
In the first step, a function get_word_frequencies() is defined in order to count the number of times a certain word appears.
File 'filen.txt' is open and read by built-in functions.
The words, after converting to lower case and removing commas and full stops, are converted to a list using split function.
The list of words are iterated through a for loop ignoring the common words like the,a etc.
The count of occurence of each word is displayed in a dictionary and printed.
The function is called at the end for execution.