(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to test whether the system is a big-endian platform or little-endian platform. Sample Solution: Python Code: import sys print() if sys.byteorder == “little”: print(“Little-endian platform.”) else: print(“Big-endian platform.”) print() Sample Output: Little-endian platform Write a Python program to test whether …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to get the command-line arguments (name of the script, the number of arguments, arguments) passed to a script. Sample Solution Python Code (test.py): import sys print(“This is the name/path of the script:”),sys.argv[0] print(“Number of arguments:”,len(sys.argv)) print(“Argument List:”,str(sys.argv)) The command executed in …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to hash a word. Sample Solution Python Code: soundex=[0,1,2,3,0,1,2,0,0,2,2,4,5,5,0,1,2,6,2,3,0,1,0,2,0,2] word=input(“Input the word be hashed: “) word=word.upper() coded=word[0] for a in word[1:len(word)]: i=65-ord(a) coded=coded+str(soundex[i]) print() print(“The coded word is: “+coded) print() Sample Output: Input the word be hashed: w3r The coded …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to calculate midpoints of a line. Sample Solution Python Code: print(‘nCalculate the midpoint of a line :’) x1 = float(input(‘The value of x (the first endpoint) ‘)) y1 = float(input(‘The value of y (the first endpoint) ‘)) x2 = float(input(‘The …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to sort files by date. Sample Solution:- Python Code: import glob import os files = glob.glob(“*.txt”) files.sort(key=os.path.getmtime) print(“n”.join(files)) Sample Output: result.txt temp.txt myfile.txt mynewtest.txt mytest.txt abc.txt test.txt Python Examples for Beginners: Python Code to Add Two Numbers Free Machine Learning …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to sort three integers without using conditional statements and loops. Sample Solution Python Code: x = int(input(“Input first number: “)) y = int(input(“Input second number: “)) z = int(input(“Input third number: “)) a1 = min(x, y, z) a3 = max(x, …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to calculate the sum of the digits in an integer. Sample Solution Python Code: num = int(input(“Input a four digit numbers: “)) x = num //1000 x1 = (num – x*1000)//100 x2 = (num – x*1000 – x1*100)//10 x3 = …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to convert pressure in kilopascals to pounds per square inch, a millimeter of mercury (mmHg) and atmosphere pressure. Sample Solution Python Code: kpa = float(input(“Input pressure in in kilopascals> “)) psi = kpa / 6.89475729 mmhg = kpa * 760 …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to calculate body mass index. Sample Solution Python Code: height = float(input(“Input your height in meters: “)) weight = float(input(“Input your weight in kilogram: “)) print(“Your body mass index is: “, round(weight / (height * height), 2)) Sample Output: Input …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to convert seconds to day, hour, minutes and seconds. Sample Solution Python Code: time = float(input(“Input time in seconds: “)) day = time // (24 * 3600) time = time % (24 * 3600) hour = time // 3600 time …