Skip to main content

Posts

Showing posts with the label windows 10

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...

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

Rolling Dice Simulator (PCTS)

Python Codes The Series - 2 Photo by Brett Jordan on Unsplash Playing Ludo or Snakes & Ladders and just lost 😰 your dice 🎲; well, no need to worry till I am with you 🙋🏻‍♂️. Just use Python. Many of you might think 🤔 that I am crazy but believe me I am not crazy 😧. We will learn today to use Python for making a rolling dice simulator program.  Here, we are using random module to use the various random functions to make the probability of each outcomes equal. Copy the following code: #importing random module... import random ''' Taking a number between 1 and 10000 using randrange function ''' start = 1 end = 10000 num = random.randrange(start,end+1) #Now choosing the first digit of num from left... num_2 = str(num)[0] num_2 = int(num_2) ''' Finally, choosing the number for the die ''' if num_2 < 6: roll = random.randrange(1,num_2+1) elif num_2 == 6: roll = num_2 else: num_2 = num_2 - 3 roll = ran...

Opening Python

How to get started with the default CPython distribution Step 1: Download and install the python(3.x) from the provided link:                      https://www.python.org/downloads/ Step 2: Click on windows logo to open the start menu. Step 3: Now from there in Python(3.x) folder, click on Python idle. You can see a window of Python(3.x) idle pops up. Note: There are two modes of working in Python(3.x) idle: 1. Interactive mode: Here, you don’t have to save any python file unnecessarily in order to run it. The user can type the code directly in the idle and the output of the code would be given instantly. 2. Script mode: In script mode, the whole program is written using a number of codes and then saved in an appropriate file which is then run. Here, at last the program generally gets converted into an ‘.exe’ file. Step I: Move your cursor to the top left corner of the idle box, there click on the ...

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...