Skip to main content

Posts

Showing posts with the label Basics

SwapCase Type - I (PCTS)

 SwapCase Tutorial  S wapcase is a program to change the cases of the texts (strings), i.e. changing the capital font to small and vice versa. This program can be used to improve the basic python knowledge of python strings and can show how the swapcase() function works internally. It can be done using a lot of algorithms. I'll show you guys 2 tutorials to do the same. In this article, I'll only show the 1st method, then 2nd method will be shown in the next article which would be posted next day. > Method-I Copy the following code: #swapcase (method 1) s = input("Enter your string:") s2 = "" l = len(s) for i in range(l): if s[i].isupper()==True: s2 += s[i].lower() elif s[i].islower()==True: s2 += s[i].upper() else: s2 += s[i] print("Your string after swapping cases:",s2) ©SGPython

Diving Into Modules - Random Module

  Source:  Cyndie Meyer Random Module: This is an inbuilt module we get in the Python ecosystem and is used for bringing some variability in the program whenever required. This module is full of a ton of functions that are continuously in use in real life. Note! : To use the functions in this module, you have to import this module at least  once. The syntax for this operation is given below. Syntax: import random Some Functions in Random Module random():   This function returns a float value between 0 and 1. Syntax: x = random.random() print(x) randrange():   This function returns a random number between any given range (exclusive of the last number). Syntax: y = random.ranrange(2,7) print(y) randint():  This function returns a random number between any given range (inclusive of the last number). Syntax: z = random.randint(2,7) print(z) More functions will be continued in a later blog post... ©SGPython

For Loops

 The for loop By  polygraphus  on  shutterstock Def: The for loop is also known as the counting loop and is designed to process the items of any sequence, such as a list or a string, one by one. General form of for loop: The general form of the for loop is given below:      for <variable> in <sequence>:          statements to repeat

Character Case Swapping (PCTS)

 Python Codes The Series -1 ©Photo by wiki commons Not only in Python but also in the day-to-day life, the letters in English alphabets are characterized into two cases viz. upper case and lower case. Our first program will be a general fun program for the beginners. In this program, we will learn to swap the cases of the letters of English alphabets being entered by the user with the help of a few lines of Python code. For example: If the user enters: " hoLa AmIGo" , the python program would convert this string into " HOlA aMigO" . The Program is noted below: string=input("Enter a string :") length=len(string) s='' for i in range(length): if string[i].islower(): s=s+string[i].upper() elif string[i].isupper(): s=s+string[i].lower() else: s=s+string[i] print(s) FOR QUICK REFERENCE: The len() function gives the length of the string and the the input() function takes input from the user. Hope you like i...

Basics of Python - 1

 Data types in Python Datatypes are the attributes or  group of specific characters in computer science which tells the compiler or the interpreter about the type of data in which the user want a specific character to be used. Whenever a specific datatype is mentioned by the user, the compiler or the interpreter converts the data to the specific type to be read by the computer. It plays a very vital role in the conversation between the computer and the programmer and without having sufficient types of data it would be really confusing to program any code at all.   The built-in core datatypes provided in Python are: String Numbers List Tuple Dictionary String A string datatype literally holds the actual string data (which may be letters, numbers or special symbols) inside "" or inside '' ,i.e. inside double or single quotation marks. For example: All the following strings are legal and acceptable in Python: "Hello","Holla",'I am great.'...

Our view towards Python (as a programming language)

  Python - The language of the future Introduction When we hear the term programming language, we usually talk about high-level programming language which are those programming language having a lucid (or easy-to-read) syntax and are later converted to low-level language (binary) , which is understandable by the computer.  Programming language has always been an area of interest over the passing years since the very early days of ' Fortran ' (created by John Backus at  IBM ). To this day, dozens of programming language has been created by different 'Computer Scientists' around the world. What is Python? What is Python? Many of you will describe a large scary snake 🐍, which isn't actually wrong 😅. But here we are talking about a programming language. Similarly, Python is also a high-level and interepreted programming language created by  Guido van Rossum in the late 1980s . It was first released in 1991 as a successor to ABC Programming language . It known fo...