Day: February 13, 2021

Python Example – Write a Python program to input a number, if it is not a number generate an error message

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to input a number, if it is not a number generate an error message.   Sample Solution Python Code: while True: try: a = int(input(“Input a number: “)) break except ValueError: print(“\nThis is not a number. Try again…”) print() Sample Output: …

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

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to remove the first item from a specified list.   Sample Solution Python Code: color = [“Red”, “Black”, “Green”, “White”, “Orange”] print(“\nOriginal Color: “,color) del color[0] print(“After removing the first color: “,color) print() Sample Output: Original Color: [‘Red’, ‘Black’, ‘Green’, ‘White’, …

Python Example – Write a Python program to make file lists from current directory using a wildcard

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to make file lists from current directory using a wildcard.   Sample Solution Python Code: import glob file_list = glob.glob(‘*.*’) print(file_list) Sample Output: [’30eb5e10-2675-11e7-a9c1-cf681af3cdf1.py’, ‘test.txt’, ‘abc.py’, ‘ mynewtest.txt’, ‘myfile.txt’, ‘logging_example.out’, ’35ba4b40-2675 -11e7-a9c1-cf681af3cdf1.py’, ’30c8bae0-2675-11e7-a9c1-cf681af3cdf1. py’, ‘abc.txt’, ‘exercise.cs’, ‘Example.cs’, ‘myfig.png’, ‘file.out ‘, ‘line.gif’, …

Python Example – Write a Python program to get numbers divisible by fifteen from a list

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get numbers divisible by fifteen from a list.   Sample Solution Python Code: num_list = [45, 55, 60, 37, 100, 105, 220] result = list(filter(lambda x: (x % 15 == 0), num_list)) print(“Numbers divisible by 15 are”,result) Sample Output: Numbers …

Python Example – Write a Python program to check if a number is positive, negative or zero

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check if a number is positive, negative or zero.   Sample Solution Python Code: num = float(input(“Input a number: “)) if num > 0: print(“It is positive number”) elif num == 0: print(“It is Zero”) else: print(“It is a negative …

Python Example – Write a Python program to retrieve file properties

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to retrieve file properties.   Sample Solution Python Code: import os.path import time print(‘File :’, __file__) print(‘Access time :’, time.ctime(os.path.getatime(__file__))) print(‘Modified time:’, time.ctime(os.path.getmtime(__file__))) print(‘Change time :’, time.ctime(os.path.getctime(__file__))) print(‘Size :’, os.path.getsize(__file__)) Sample Output: File : 8dbacd90-266d-11e7-a9c1-cf681af3cdf1.py Access time : Fri Apr 21 …