Skip to main content

python prgram for matrix addition (user based input )without using numpy or array

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 13 14:25:56 2018

@author: beast
Note this program is for holding int value to list only """
def addmatrix():
    matrixA=list() # intialize matrix as empty list
    matrixB=list() #intialize matrix as empty 
    matrixS=list() #store the sum 
    
    try:
        row,col=[int(j) for j in (input("Enter the row and col ").split())]
        print(row,col)
        inp=""
    except ValueError:
            print("Please Enter row and col seperated by space eg: 2 2") 
            inmatrix()
    
    for i in range(row):
        for j in range(col):
                inp+=((input("Enter the number for matrix A[%d][%d}--->"%(i,j)))+",")
        try:
            lst=[int(a) for a in inp.split(",") if a!=""]#delete int for making it to hold any data 
            # create a list using input row string 
            matrixA.append(lst) #add the row wise data 
            inp="" #after eacch row input reset inp to get next input 
        except ValueError:
            print("please Enter Integer Only as list input\n\a------ Restarting ---\n")
            addmatrix()
       
            
#        """now matrix B input ----"""
    print("\n____________________\n")
    for k in range(row):
        for l in range(col):
                inp+=(input("Enter the number for matrix B[%d][%d}--->"%(k,l))+",")
        try:
            lst=[int(a) for a in inp.split(",") if a!=""]#delete int for making it to hold any data 
            # create a list using input row string 
            matrixB.append(lst) #add the row wise data 
            inp="" #after eacch row input reset inp to get next input 
        except ValueError:
            print("please Enter Integer Only as list input\n\a------ Restarting ---\n")
            addmatrix()
    print("\n------------\nmatrix A-->\n",matrixA) 
    print("\nmatrix B-->\n",matrixB) 
        
    for m in range(row):
        temp=list()
        for n in range(col):
             temp.append(matrixA[m][n]+matrixB[m][n])
          
        matrixS.append(temp) # add the result rowwise as a list 
    print("\n-----------result----------\n")
    
#    print(matrixS)        
    return matrixS
    

    
if __name__=="__main__":
    try:
        print(addmatrix())   
    except Exception:
        print("please Give Correct Input\n")
        addmatrix()

Comments

Popular posts from this blog

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by majority of expert bloggers for their website monetization because it is a cookie based contextual advertising system that shows targeted ads relevant to the content and reader. As bloggers are paid on per click basis, they try various ad placements on the blog to  increase the revenue  and get maximum clicks on the ad units. Well, on some blogs, you might have seen Adsense ad units placed below the post title. Do you know why? It is because the area just below the post title gets the most exposure and is the best place to put AdSense ad units to increase  Click Through Rate (CTR). Even though ads below post title work like a charm but this doesn’t mean that it will work for you as well. If you want to find out the best AdSense ads placement for your blog, try experimenting by placing ads at various locations such as header, sidebar, footer, etc. You can try other  blog monetization methods  as well to effectively monetize y...

13 websites to register your free domain

Register your Free Domain Now!! 1)  .tk Dot TK is a FREE domain registry for websites on the Internet. It has exactly the same power as other domain extensions, but it’s free! Because it’s free, millions of others have been using .TK domains since 2001 – which makes .TK powerful and very recognizable.  Your website will be like www.yourdomainname.tk . It is free for 1 year. It’s a ccTLD domain whixh having the abbreviation  Tokelau. To create a .tk domain, Visit   www.dot.tk 2) co.cc Co.cc is completely free domain which is mostly used by blogspot bloggers because of it’s easy to use DNS system. Creating a co.cc for blogger is simple ( for instructions- “click here”). Your website will be like www.yourdomainname.co.cc . To create a .co.cc domain, visit www.co.cc 3)   co.nr co.nr is too like co.cc. Your website will be like  www.yourdomainname.co.nr . You can add it for blogger also.. To create a .co.cc domain, vi...

50 intesting facebook facts

some facts about facebook if u type @[4:0] in any facebook comment box it will write mark zukerburg 1 in every 13 people on Earth is on Facebook 35+ demographic represents more than 30% of the entire user base 71.2 % of all USA internet users are on Facebook In 20 minutes 1,000,000 links are shared on Facebook In 20 minutes 1,484,000 event invites are posted In 20 minutes 1,323,000 photos are tagged In 20 minutes 1,851,000 status updates are entered In 20 minutes 1.972 million friend requests are accepted In 20 minutes 2,716,000 photos are uploaded In 20 minutes 2,716,000 messages are sent In 20 minutes 10.2 million comments are posted In 20 minutes 1,587,000 wall posts are written 750 million photos were uploaded to Facebook over New Year’s weekend 48% of young Americans said they found out about news through Facebook 48% of 18 to 34 year olds check Facebook right when they wake up 50% of active users log on to Facebook in any given day Average user has 130 friends ...

C++ Program to Find HCF and LCM among 4 numbers (Easiest Logic)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 #include <iostream> #include <math.h> using namespace std; int main () { int a,b,c,d,i,j,minimum; cout << "Enter the all four number " ; cin >> a >> b >> c >> d; if (a < b && a < c && a < d) minimum = a; else if (b < c && b < d) minimum = b; else if (c < d) minimum = c; else minimum = d; for (j = minimum;; -- j) { if (a % j == 0 && b % j == 0 && c % j == 0 && d % j == 0 ) { break ; } } for (i = 1 ;;i ++ ) { if (i % a == 0 && i % b == 0 && i % c == 0 && i % d == 0 ) break ; } cout << "Lowest Common factor=>" << i << endl; ...

USE any TRIAL SOFTWARE FOREVER WITHOUT SERIAL NUMBER

USE any TRIAL SOFTWARE FOREVER WITHOUT SERIAL NUMBER(most wanted trick) Run a trial software forever now with time stopper you can run a trial software forever no need to fetch for serial numbers,activation codes,patch just DOWNLOAD TIME STOPPER now open it install it click browse select the .exe of the software or file which you want to run forever now simply click create desktop icon and now delete all its existing shortcuts now have fun enjoying software for life time

python program to Print Starting Series OF Indian Mobile Number for a State or operator or both

import requests import urllib.request import time from bs4 import BeautifulSoup as bs import re url = ' https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India' state_to_extract = "UE" #if set to None all state is considered telecom_to_extracted = None #if set to none all operator from particular city is extracted response = requests . get(url) print (response) soup = bs(response . text, "html.parser" ) one_a_tag = soup . findAll( 'tr' )[ 35 :] lst = [] for k in one_a_tag: s = k . findAll( 'td' ) limit = len (s) i = 0 while True : if i == limit: break no = s[i] . text i += 1 if i == limit: break operator = s[i] . text i += 1 if i == limit: break state = s[i] . text i += 1 if i == limit: break res = f "{no} {operator} {state}" if state_to_extract is None : if telecom_to_extracted is None : lst . append(no) elif telecom_to_e...

30 Terrific Twitter Facts And Figures

Twitter has always suffered an image problem and is not usually taken very seriously by the general public. Its name doesn’t help with some people even saying that ‘Twitter is for twits’. Despite this glamor and brand problem this has not held back its growth after its humble origins and launch in 2006. Since then Twitter has gained popularity worldwide and is estimated to have 225 million users, generating 65 million tweets a day and handling over 800,000 search queries per day. It is sometimes described as the “SMS of the Internet” and its 140 character limit keeps the messages short and simple. Its attraction as a social web media platform is maybe in its simplicity and real time messaging that enables breaking news and information to hit the web instantly without filt30 Terrific Twitter Facts and Figures:- Twitter was created in March 2006 by Jack Dorsey and launched in July of that year. Twitter’s origins lie in a “day long brainstorming session” that was held by board...

12 Tips to Maintain a Virus Free Computer

1. Email is one of the common ways by which your computer can catch a virus . So it is always recommended to stay away from SPAM. Open only those emails that has it’s origin from a trusted source such as those which comes from your contact list. If you are using your own private email host (other than gmail, yahoo, hotmail etc.) " then it is highly recommended that you use a good anti-spam software. And finally NEVER click on any links in the emails that comes from untrusted sources. 2. USB thumb/pen drives is another common way by which viruses spread rapidly." So it is always a good habit to perform a virus scan before copying any data onto your computer. NEVER double-click the pen drive to open it. Instead right-click on it and select the option “open”. This is a safe way to open a pen drive. 3. Be careful about using MS Outlook. Outlook is more susceptible to worms than other e-mail programs, unless you have efficient Anti-Virus programs running. Use Pegasus ...