Day: February 13, 2021

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

Hits: 8 (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() …

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

Hits: 4 (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’, …

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

Hits: 7 (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 …

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

Hits: 4 (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 …

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

Hits: 0 (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 …

Python Example – Write a Python program to retrieve file properties

Hits: 8 (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 …