Sunday, May 22, 2022

Anaconda Installation

In this post we will discuss about Anaconda and its installation.

Anaconda comes with number of applications(jupyter notebook included), data science and machine learning packages.

Applications in Anaconda

Follow these simple steps to install anaconda.

Step 1: Go to anaconda downloads page.

https://www.anaconda.com/products/distribution

Step 2:Click on the download for windows button. Your download will start.


Step 3:Once download is complete, double click on the executable file in your downloads folder.


Step 4:Click Next, Agree to the service agreement, Select just me in installation type.



Step 5:Choose your folder in which you want to install anaconda. You can also leave it to the default location. Click next. In the advanced Installation Options, Check both the options and click install.

Installation might take a while, once installation is complete go to the windows search bar and search for anaconda. You will see a window opened that shows all the applications that comes with anaconda.

Tuesday, July 20, 2021

Program on String Functions.


Understanding string functions. 

 

isalnum() - returns True if character is alphabet or number.

in a string, returns True if string contains only letters and alphabets.

                    returns False if string contains special characters.

                    string="abg1234".isalnum()    #returns True

                    string="abg12@#$34".isalnum()    #returns False

isalpha() - returns True if character is an alphabet.

isdigit() - returns True if character is a number.

islower() - returns True if character is a lower case alphabet.

isupper() - returns True if character is a upper case alphabet.

 

Input Format

A single line containing a string 

Output Format

In the first line, print True if string has any alphanumeric characters. Otherwise, print False.

In the second line, print True if string has any alphabetical characters. Otherwise, print False.

In the third line, print True if string has any digits.Otherwise, print False.

In the fourth line, print True if string has any lowercase characters. Otherwise, print False.

In the fifth line, print True if string has any uppercase characters. Otherwise, print False

 

Sample Input:

qA2

Sample Output:

True

True

True

True

True

 

Solution:

if __name__ == '__main__':
    s = input()
    r1=False
    r2=False
    r3=False
    r4=False
    r5=False
    for i in range(0,len(s)):
        if(s[i].isalnum()):
            r1=True
        if(s[i].isalpha())and(s[i].islower()):
            r2=True
            r4=True
        elif(s[i].isalpha())and(s[i].isupper()):
            r2=True
            r5=True
        elif(s[i].isnumeric()):
            r3=True
    print(r1)
    print(r2)
    print(r3)
    print(r4)
    print(r5)
 

 

Sunday, July 18, 2021

File handling

Python has many functions for file handling.

for any file operation, initially the file must be opened.


open() function opens an existing file.

my_file=open("Sample.txt")  is the syntax to open a file.

open() function takes two parameters.

  1. file name
  2. mode 

mode is the mode in which you want to open the file which can be any of the following.

  • read - r - opens file in reading mode, if file is not present gives error

  • write - w - opens file in writing mode, if file is not present gives error

  • append - a - opens file for appending, if file is not present gives error

  • create - x - creates file, if file is already present gives error

You cannot write into the file if the file is opened in read/append mode.

You cannot perform read operation on the file opened in writing/append mode.

You cannot perform append operation, if the file is opened in read/write mode.

This is my sample.txt file. 

 


 

 

How to read and modify the content in the files 

  • read a file

  • write into a file - write,append

  • close

  • delete

 

1)Reading a file.

in file opened with read mode:

  • read() function reads the entire file.

  • read(15) reads only the first 15 characters in the file.

  • readline() reads the first line in the file.


 

2)Writing into a file.

in a file opened with write mode

write() function rewrites the file with new content.

in a file opened with append mode

write() function appends the new content to end of the file.


 

3)Closing a file.

close() is used to close a file.

when ever the file is read the object will be pointing to end of the file.

So performing read operation again will result in empty string.

Whenever the file is closed the object will point again to the beginning of the file.

 


 

4)Deleting a file.

To delete a file import os module and call remove() function.

import os

os.remove("Sample.txt")

To delete the folder call rmdir() function

import os

os.rmdir("Newfolder")

 

Video explanation :  https://youtu.be/dschu28WCIg


 

 



Anaconda Installation

In this post we will discuss about Anaconda and its installation. Anaconda comes with number of applications(jupyter notebook included), dat...