[Link]
php
[Link] a Python function to find the maximum of three numbers.
2. Write a Python program that accepts a hyphen-separated sequence of words as input and prints the
words in a hyphen-separated sequence after sorting them alphabetically.
Sample Items : green-red-yellow-black-white
Expected Result : black-green-red-white-yellow
3. Python program to display calendar
import calendar
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
print([Link](yy,mm))
4. Write a Python function that prints out the first n rows of Pascal's triangle.
Note : Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal.
Sample Pascal's triangle :
Each number is the two numbers above it added together
5. Write a Python function that accepts a string and counts the number of upper and lower case letters.
def string_test(s):
UCASE, LCASE = 0
for c in s:
if [Link]():
UCASE += 1
elif [Link]():
LCASE += 1
else:
pass
print("Original String: ", s)
print("No. of Upper case characters: ", UCASE)
print("No. of Lower case Characters: ", LCASE)
string_test('The quick Brown Fox')
6. Write a Python function to check whether a string is a pangram or not.
Note : Pangrams are words or sentences containing every letter of the alphabet at least once.
For example : "The quick brown fox jumps over the lazy dog"
[Link] a Python program to access a function inside a function.
[Link] a Python program to detect the number of local variables declared in a function.
9. Write a Python program that invokes a function after a specified period of time.
Sample Output:
Square root after specific miliseconds:
4.0
10.0
158.42979517754858
[Link]
10. Python Program to Find LCM of 2 numbers.
11. Python Program to Display Calendar
Recursion:
[Link] Program to Display Fibonacci Sequence Using Recursion
[Link] Program to Find Factorial of Number Using Recursion
[Link] Program to Calculate the Power of a Number Using Recursion
Python Number Programs
[Link] program to check if the given number is a Disarium Number
[Link] program to check if the given number is Happy Number
1. def isHappyNumber(num):
2. rem = sum = 0;
3.
4. #Calculates the sum of squares of digits
5. while(num > 0):
6. rem = num%10;
7. sum = sum + (rem*rem);
8. num = num//10;
9. return sum;
10.
11. num = 82;
12. result = num;
13.
14. while(result != 1 and result != 4):
15. result = isHappyNumber(result);
16.
17. #Happy number always ends with 1
18. if(result == 1):
19. print(str(num) + " is a happy number");
20. #Unhappy number ends in a cycle of repeating numbers which contain 4
21. elif(result == 4):
22. print(str(num) + " is not a happy number");
Output:
82 is a happy number
[Link] program to determine whether the given number is a Harshad Number
20.
1. #Initialize array
2. arr = [1, 2, 3, 4, 2, 7, 8, 8, 3];
3.
4. print("Duplicate elements in given array: ");
5. #Searches for duplicate element
6. for i in range(0, len(arr)):
7. for j in range(i+1, len(arr)):
8. if(arr[i] == arr[j]):
9. print(arr[j]);
Output:
Duplicate elements in given array:
2
3
8