Tag Archives: python example

Python Example – Write a Python program to check the validity of a password (input from users)

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check the validity of a password (input from users). Validation : At least 1 letter between [a-z] and 1 letter between [A-Z]. At least 1 number between [0-9]. At least 1 character from [$#@]. Minimum length 6 characters. Maximum length …

Python Example – Write a Python program that accepts a string and calculate the number of digits and letters

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program that accepts a string and calculate the number of digits and letters.   Sample Solution: Python Code: s = input(“Input a string”) d=l=0 for c in s: if c.isdigit(): d=d+1 elif c.isalpha(): l=l+1 else: pass print(“Letters”, l) print(“Digits”, d) Sample Output: …

Python Example – Write a Python program to count the number of even and odd numbers from a series of numbers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to count the number of even and odd numbers from a series of numbers.   Sample Solution: Python Code: numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple count_odd = 0 count_even = 0 for …

Python Example – Write a Python program that accepts a word from the user and reverse it

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program that accepts a word from the user and reverse it.   Sample Solution: Python Code: word = input(“Input a word to reverse: “) for char in range(len(word) – 1, -1, -1): print(word[char], end=””) print(“n”) Sample Output: Input a word to reverse: …

Python Example – Write a Python program to convert temperatures to and from celsius, fahrenheit.

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to convert temperatures to and from celsius and fahrenheit.   Python: Centigrade and Fahrenheit Temperatures : The centigrade scale, which is also called the Celsius scale, was developed by Swedish astronomer Andres Celsius. In the centigrade scale, water freezes at 0 …

Python Example – Write a Python program to find those numbers which are divisible by 7 and multiple of 5

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700 (both included).   Sample Solution: Python Code: nl=[] for x in range(1500, 2701): if (x%7==0) and (x%5==0): nl.append(str(x)) print (‘,’.join(nl)) Sample Output: 1505,1540,1575,1610,1645,1680,1715,1750,1785,1820,1855,1890,1925,1960,1995,2030,2065,2100,2135,2170,2205,2240, 2275,2310,2345,2380,2415,2450,2485,2520,2555,2590,2625,2660,2695 …

Python Example – Write a Python program to find the first duplicate element in a given array of integers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find the first duplicate element in a given array of integers. Return -1 If there are no such elements.   Sample Solution: Python Code : def find_first_duplicate(nums): num_set = set() no_duplicate = -1 for i in range(len(nums)): if nums[i] in …