Skip to main content

Posts

Showing posts with the label functions

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 - Math Module

 >Math Module - Overall explanation Source:  freepik Introduction Other than Python built-in functions, there are numerous functions which can be found in some packages which need to be imported when needed which are called modules .  Such a module in python is the math module. Python's standard library provides a module viz. math for math functions that work with all number types except complex numbers. The Math module in Python is enriched with plenty of functions. Note!: To use the math module one must import it first into the Python compiler one has been working with. The syntax to do so is given below: import math FUNCTIONS IN MATH MODULE ceil(): This function returns the closest just above integer when a value has been passed. Syntax: x = math.ceil(2.4) print(x) floor():  This function returns the closest just below integer when a value has been passed. Syntax: y = math.floor(2.4) print(y) fabs():  This function returns the absolute number in flo...