Day: February 17, 2021

Python Example – Write a Python program to list home directory without absolute path

Hits: 9 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to list home directory without absolute path.   Sample Solution Python Code: import os.path print(os.path.expanduser(‘~’)) Sample Output: /home/students   Write a Python program to list home directory without absolute path Free Machine Learning & Data Science Coding Tutorials in …

Python Example – Write a Python program to add trailing and leading zeroes to a string

Hits: 10 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to add trailing and leading zeroes to a string.   Sample Solution Python Code: str1=’122.22′ print(“Original String: “,str1) print(“\nAdded trailing zeros:”) str1 = str1.ljust(8, ‘0’) print(str1) str1 = str1.ljust(10, ‘0’) print(str1) print(“\nAdded leading zeros:”) str1=’122.22′ str1 = str1.rjust(8, ‘0’) …

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

Hits: 4 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check whether lowercase letters exist in a string.   Sample Solution Python Code: str1 = ‘A8238i823acdeOUEI’ print(any(c.islower() for c in str1)) Sample Output: True   Write a Python program to check whether lowercase letters exist in a string …

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

Hits: 17 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check whether multiple variables have the same value.   Sample Solution Python Code: x = 20 y = 20 z = 20 if x == y == z == 20: print(“All variables have same value!”) Sample Output: All …

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

Hits: 5 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to determine the largest and smallest integers, longs, floats. Sample Solution Python Code: import sys print(“Float value information: “,sys.float_info) print(“\nInteger value information: “,sys.int_info) print(“\nMaximum size of an integer: “,sys.maxsize) Sample Output: Float value information: sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250 738585072014e-308, …