Tag Archives: Python tutorials

Python Exercise: Test whether a number is within 100 of 1000 or 2000

  (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to test whether a number is within 100 of 1000 or 2000. Python abs(x) function: The function returns the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a …

Python Exercise: Get the the volume of a sphere with radius

  (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the the volume of a sphere with radius 6. Python: Volume of a Sphere A sphere is a three-dimensional solid with no face, no edge, no base and no vertex. It is a round body with all points …

Python Exercise: Calculate number of days between two dates

  (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to calculate number of days between two dates. Python datetime.date(year, month, day) : The function returns date object with same year, month and day. All arguments are required. Arguments may be integers, in the following ranges: MINYEAR <= year <= MAXYEAR 1 <= month <= 12 1 <= day <= number of days in the given month and year   …

Python Exercise: Print the calendar of a given month and year

  (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to print the calendar of a given month and year. Note: Use ‘calendar’ module. Python calendar.month(theyear, themonth, w=0, l=0): The function returns a month’s calendar in a multi-line string using the formatmonth() of the TextCalendar class. ‘l’ specifies the number …

Python Exercise: Display the first and last colors from a given list

  (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to display the first and last colors from the following list. color_list = [“Red”,”Green”,”White” ,”Black”] Sample Solution:- Python Code: color_list = [“Red”,”Green”,”White” ,”Black”] print( “%s %s”%(color_list[0],color_list[-1])) Sample Output: Red Black   Display the first and last colors from a given …

Python Exercise: Generate a list and tuple with comma-separated numbers

  (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers. Sample data: 3, 5, 7, 23 Python list: A list is a container which holds comma separated values (items or elements) between square brackets …

Python Examples for Beginners: Python Code to Print Hello world

(Python Tutorials for Citizen Data Scientist) Python Code to Print Hello world! A simple program that displays “Hello, World!”. It’s often used to illustrate the syntax of the language. Source Code # This program prints Hello, world! print(‘Hello, world!’) Output Hello, world! In this program, we have used the built-in print() function to print the string Hello, world! on …

Python Basics for Beginners – Python | Basic Operators

Python Basics for Beginners – Python | Basic Operators Operators are the constructs which can manipulate the value of operands. Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator. Types of Operator Python language supports the following types of operators. Arithmetic Operators Comparison (Relational) …

Python Basics for Beginners – Python | Variable Types

Python Basics for Beginners – Python | Variable Types Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. …

Python Vs R – Which should I learn for Business Data Analytics?

R Vs Python – Which should I learn for Business Data Analytics? Now, it’s the time for a battle of two most demanding programming languages that is R vs Python. We will go deep in understanding the differences between the two languages. And, I assure you that you will not have any confusion left after …