Python Basic Exercises, Practice, Solution

Python Basic Exercises, Practice, Solution

Write a Python program to get the Python version you are using

Write a Python program to print the following string in a specific format

Write a Python program to display the current date and time

Write a Python program which accepts the radius of a circle from the user and compute the area.

Write a Python program to print first and last name in reverse order with a space between them

Write a python program to generate a list and tuple with comma-separated numbers

Write a Python program to accept a filename from the user and print the extension of that

Write a Python program to display the first and last colors from the following list

Write a Python program to display the examination schedule

Write a Python program that accepts an integer n and computes the value of n+nn+nnn

Write a Python program to print the calendar of a given month and year

Write a Python program to calculate number of days between two dates.

Write a Python program to get the volume of a sphere with radius 6

Write a Python program to test whether a number is within 100 of 1000 or 2000

Write a Python program to calculate the sum of three given numbers

Write a Python program to get a newly-generated string from a given string where “Is” has been added to the front. Return the string unchanged if the given string already begins with “Is”.

Write a Python program that returns a string that is n (non-negative integer) copies of a given string.

Write a Python program that determines whether a given number (accepted from the user) is even or odd, and prints an appropriate message to the user.

Write a Python program to count the number 4 in a given list.

Write a Python program to get n (non-negative integer) copies of the first 2 characters of a given string. Return n copies of the whole string if the length is less than 2.

Write a Python program to test whether a passed letter is a vowel or not

Write a Python program that checks whether a specified value is contained within a group of values.

Write a Python program to create a histogram from a given list of integers.

Write a Python program that concatenates all elements in a list into a string and returns it.

Write a Python program to print all even numbers from a given list of numbers in the same order and stop printing any after 237 in the sequence.

Write a Python program that prints out all colors from color_list_1 that are not present in color_list_2.

Write a Python program that will accept the base and height of a triangle and compute its area.

Write a Python program that computes the greatest common divisor (GCD) of two positive integers.

Write a Python program to find the least common multiple (LCM) of two positive integers.

Write a Python program to sum three given integers. However, if two values are equal, the sum will be zero.

Write a Python program to sum two given integers. However, if the sum is between 15 and 20 it will return 20.

Write a Python program that returns true if the two given integer values are equal or their sum or difference is 5.

Write a Python program to add two objects if both objects are integers.

Write a Python program that displays your name, age, and address on three different lines.

Write a Python program to compute the future value of a specified principal amount, rate of interest, and number of years.

Write a Python program to calculate the distance between the points (x1, y1) and (x2, y2).

Write a Python program to check whether a file exists.

Write a Python program to determine if a Python shell is executing in 32bit or 64bit mode on OS.

Write a Python program to get OS name, platform and release information.

Write a Python program to locate Python site packages.

Write a Python program that calls an external command.

Write a Python program to retrieve the path and name of the file currently being executed

Write a Python program to find out the number of CPUs used

Write a Python program to parse a string to float or integer.

Write a Python program to list all files in a directory.

Write a Python program to print without a newline or space.

Write a Python program to determine the profiling of Python programs.

Write a Python program to print to STDERR.

Write a Python program to access environment variables.

Write a Python program to get the current username.

Write a Python program to find local IP addresses using Python’s stdlib.

Write a Python program to get the height and width of the console window

Write a Python program to get the execution time of a Python method.

Write a Python program to sum the first n positive integers.

Write a Python program to convert height (in feet and inches) to centimeters.

Write a Python program to calculate the hypotenuse of a right angled triangle

Write a Python program to convert the distance (in feet) to inches, yards, and miles.

Write a Python program to convert all units of time into seconds.

Write a Python program to get an absolute file path

Write a Python program that retrieves the date and time of file creation and modification.

Write a Python program that converts seconds into days, hours, minutes, and seconds.

Write a Python program to calculate the body mass index.

Write a Python program to convert pressure in kilopascals to pounds per square inch, a millimeter of mercury (mmHg) and atmosphere pressure.

Write a Python program to calculate sum of digits of a number.

Write a Python program to sort three integers without using conditional statements and loops.

Write a Python program to sort files by date.

Write a Python program to get a directory listing, sorted by creation date.

Write a Python program to get the details of the math module.

Write a Python program to calculate the midpoints of a line.

Write a Python program to hash a word.

Write a Python program to get the copyright information and write Copyright information in Python code.

Write a Python program to get the command-line arguments (name of the script, the number of arguments, arguments) passed to a script.

Write a Python program to test whether the system is a big-endian platform or a little-endian platform.

Write a Python program to find the available built-in modules.

Write a Python program to get the size of an object in bytes.

Write a Python program to get the current value of the recursion limit.

Write a Python program to concatenate N strings.

Write a Python program to calculate the sum of all items of a container (tuple, list, set, dictionary).

Write a Python program to test whether all numbers in a list are greater than a certain number.

Write a Python program to count the number of occurrences of a specific character in a string.

Write a Python program to check whether a file path is a file or a directory.

Write a Python program to get the ASCII value of a character.

Write a Python program to get the size of a file.

Given variables x=30 and y=20, write a Python program to print “30+20=50”.

Write a Python program to perform an action if a condition is true. Given a variable name, if the value is 1, display the string “First day of a Month!” and do nothing if the value is not equa

Write a Python program to create a copy of its own source code.

Write a Python program to swap two variables.

Write a Python program to define a string containing special characters in various forms.

Write a Python program to get the Identity, Type, and Value of an object.

Write a Python program to convert the bytes in a given string to a list of integers.

Write a Python program to check whether a string is numeric.

Write a Python program to print the current call stack.

Write a Python program to list the special variables used in the language.

Write a Python program to get system time.

Write a Python program to clear the screen or terminal.

Write a Python program to get the name of the host on which the routine is running.

Write a Python program to access and print a URL’s content to the console.

Write a Python program to get system command output.

Write a Python program to extract the filename from a given path.

Write a Python program to get the effective group id, effective user id, real group id, and a list of supplemental group ids associated with the current process.

Write a Python program to get the users environment

Write a Python program to divide a path by the extension separator.

Write a Python program to retrieve file properties.

Write a Python program to find the path to a file or directory when you encounter a path name.

Write a Python program to find the path to a file or directory when you encounter a path name

Write a Python program to get numbers divisible by fifteen from a list using an anonymous function.

Write a Python program to make file lists from the current directory using a wildcard.

Write a Python program to remove the first item from a specified list.

Write a Python program that inputs a number and generates an error message if it is not a number.

Write a Python program to filter positive numbers from a list.

Write a Python program to compute the product of a list of integers (without using a for loop).

Write a Python program to print Unicode characters.

Write a Python program to prove that two string variables of the same value point to the same memory location.

Write a Python program to create a bytearray from a list.

Write a Python program to round a floating-point number to a specified number of decimal places.

Write a Python program to format a specified string and limit the length of a string.

Write a Python program to determine if a variable is defined or not.

Write a Python program to empty a variable without destroying it.

Write a Python program to determine the largest and smallest integers, longs, and floats.

Write a Python program to check whether multiple variables have the same value.

Write a Python program to sum all counts in a collection.

Write a Python program to get the actual module object for a given object.

Write a Python program to check whether an integer fits in 64 bits.

Write a Python program to check whether lowercase letters exist in a string.

Write a Python program to add leading zeroes to a string.

Write a Python program that uses double quotes to display strings.

Write a Python program to split a variable length string into variables.

Write a Python program to list the home directory without an absolute path.

Write a Python program to calculate the time runs (difference between start and current time) of a program.

Write a Python program to input two integers on a single line.

Write a Python program to print a variable without spaces between values.

Write a Python program to find files and skip directories in a given directory.

Write a Python program to extract a single key-value pair from a dictionary into variables.

Write a Python program to convert true to 1 and false to 0

Write a Python program to validate an IP address.

Write a Python program to convert an integer to binary that keeps leading zeros.

Write a python program to convert decimal to hexadecimal.

Write a Python program to check if every consecutive sequence of zeroes is followed by a consecutive sequence of ones of same length in a given string. Return True/False.

Write a Python program to determine if the Python shell is executing in 32-bit or 64-bit mode on the operating system.

Write a Python program to check whether a variable is an integer or string.

Write a Python program to test if a variable is a list, tuple, or set.

Write a Python program to find the location of Python module sources.

Write a Python function to check whether a number is divisible by another number. Accept two integer values from the user.

Write a Python function to find the maximum and minimum numbers from a sequence of numbers

Write a Python function that takes a positive integer and returns the sum of the cube of all positive integers smaller than the specified number.

Write a Python function to check whether a distinct pair of numbers whose product is odd is present in a sequence of integer values.

Leave a Comment