Skip to main content

python program to take nested list input ...(nested list addition ,substraction etc)

 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
#!/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 inmatrix():
    matrixA=list() # intialize matrix as empty list
   
    
    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--->"))+",")
        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")
            inmatrix()
    return matrixA
#    print(matrixA)     

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

this below code is alternate version for accepting anything(character as nested list input )..

 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
#!/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 inmatrix():
    matrixA=list() # intialize matrix as empty list
   
    
    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--->"))+",")
        try:
            lst=[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 Exception:
            print("\n--AN ERROR occured while taking input to list,please try again\n")
            inmatrix()
    return matrixA
#    print(matrixA)     

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

Comments

Popular posts from this blog

3g what it is

Definition of 3G: 3G is the third generation of wireless technologies. It comes with enhancements over previous wireless technologies, like high-speed transmission, advanced multimedia access and global roaming. 3G is mostly used with mobile phones and handsets as a means to connect the phone to the Internet or other IP networks in order to make voice and video calls, to download and upload data and to surf the net. How is 3G Better?: 3G has the following enhancements over 2.5G and previous networks: Several times higher data speed; Enhanced audio and video streaming; Video-conferencing support; Web and WAP browsing at higher speeds; IPTV (TV through the Internet) support. 3G Technical Specifications: The transfer rate for 3G networks is between 128 and 144 kbps (kilobits per second) for devices that are moving fast and 384 kbps for slow ones(like for pedestrians). For fixed wireless LANs, the speed goes beyond 2 Mbps. 3G is a set of technologies and stand

Dragon Age: Inquisition Digital Deluxe Edition + All DLCs (torrent) Repack Size: 20.1~23.9 GB

Brief : Dragon Age: Inquisition  is an  action role-playing video game  developed by  Bioware Edmonton  and published by  Electronic Arts . The third major game in the  Dragon Age  franchise,  Dragon Age: Inquisition  is the sequel to  Dragon Age: Origins  and  Dragon Age II . The game was released worldwide in November 2014 for  Microsoft Windows ,  PlayStation 3 ,  PlayStation 4 ,  Xbox 360 , and  Xbox One . Repack Size: 20.1~23.9 GB 

How to Create Your Own Customized Run Commands

The Run command on Microsoft Windows operating system allows you to directly open an application or document with just a single command instead of navigating to it’s location and double-clicking the executable icon. However, it only works for some of the inbuilt Windows programs such as Command prompt (cmd), Calculator (calc) etc. So, have you ever wondered how to create your own customized Run commands for accessing your favorite programs, files and folders? Well, read on to find out the answer. Creating the Customized Run Command: Let me take up an example of how to create a customized run command for opening the Internet explorer. Once you create this command, you should be able to open the Internet explorer just by typing ie in the Run dialog box. Here is how you can do that. Right-click on your Desktop and select New -> Shortcut. You will see a “Create Shortcut” Dialog box as shown below Click on “Browse”, navigate to: Program Files -> Internet Explorer from y

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 your blog. In this tutorial, I

[solution] Motorola moto G5S plus | xt1804|Sanders Magisk error 1 : cannot mount /vendor

Error: mainly all error 1 errors. can not mount /vendors... Cause : Since your current TWRP is not treble supported ,You need a Treble supported Recovery. Solution : Simpally download this file and then flash it .  this recovery is treble supported 1. VIA TWRP boot to twrp recovery  goto install .  touch on install image and then select this downloaded file (.img)  select recovery  then flash it 2. Using fastboot fastboot flash recovery <(downloaded.img)> NOW YOU CAN FLASH MAGISK zip file via recovery LINK : TWRP_SANDERS_r22_BY_GENETIC ENGINEER

Internet Download Manager (IDM}

Internet Download Manager (IDM) is a tool to increase download speeds by up to 5 times, resume and schedule downloads. Comprehensive error recovery and resume capability will restart broken or interrupted downloads due to lost connections, network problems, computer shutdowns, or unexpected power outages. Simple graphic user interface makes IDM user friendly and easy to use.Internet Download Manager has a smart download logic accelerator that features intelligent dynamic file segmentation and safe multipart downloading technology to accelerate your downloads. Unlike other download managers and accelerators Internet Download Manager segments downloaded files dynamically during download process and reuses available connections without additional connect and login stages to achieve best acceleration performance. Internet Download Manager supports proxy servers, ftp and http protocols, firewalls, redirects, cookies, authorization, MP3 audio and MPEG video content processing. IDM integra

How to Show JavaScript or HTML Code on Blogger Blog Posts

How to Display Code on Blogger Posts In order to display codes on blogger blog you should convert them to escaped characters and show them under the HTML tag   pre  as shown below. code in escaped characters Now let us check how to convert a script in to escaped form.  How to Convert HTML/Java Script code in to Escaped Characters You can simply parse a script in to escaped format by following the changes given below. <  must be changed with   < >  should be changed with  > “  should be changed with  " In case if the script is too big to convert manually, you can use any tools which convert a Java script or HTML script in to escaped version. The following links will help you to convert normal HTML and JavaScript codes in to Escaped Characters automatically.  http://www.accessify.com/tools-and-wizards/developer-tools/quick-escape/default.php http://codeformatter.blogspot.in/2009/06/about-code-formatter.html Showing JavaScript and HTML codes in plain text

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

8 Tools to Track Registry and File Changes by installing a software

1.  Regshot unicode Regshot is a long running utility that can quickly take a before and after snapshot of the system registry. Also in the more recent unicode version it’s gained the ability to monitor for file changes using CRC32 and MD5 file checksums although this function is turned off by default and you have to go to File -> Options -> Common Options -> and tick “Check files in the specified folders” to enable it. Only the Windows folder is entered into the list of watched folders so you have to enter any others yourself through the Folders tab. This version also added the Connect to remote registry option. Regshot is very much a “hands on” utility and is more for experienced or advanced users to quickly check for system changes between two different points in time. Simply create the 1st shot, install the software or run the program you want to watch, and then press 2nd shot. After comparing the differences in the 1st and 2nd shots, it will open an HTML log in y

Google hoaxes and easter egges

Easter eggs [ edit ] Google has added many  Easter eggs  to its products and services. Calculator [ edit ] The Calculator accepts many  humorous units of measurement , including the  Beard-second  (5 nm),  Potrzebie  (2.2633 mm),  Smoot  (5 ft, 7 inches), ngogn (11.5938151 ml), blintz (36.4253863 g),  donkeypower  (250.033167 W); and the prefixes  hella - (10^27), furshlugginer- (10^6), etc. The Calculator recognizes a number of strings as numbers. They can be entered by themselves or used in expressions. They must be entered without quotation marks. When used in an expression, the phrases must be entered in lowercase. In addition to mathematical and scientific constants like  pi ,  e  and  Avogadro's number  the Calculator also accepts: "the answer to the ultimate question of life, the universe, and everything"  equals  42  as does  "the answer to life, the universe, and everything" , a reference to Douglas Adams's novel  The Hitchhiker's Gui