Python basic codes
Python basic codes
Output:
Please enter a number: 5642
Before reverse: 5642
After reverse: 2456
output:
Please enter a number: 245
The number is not an Armstrong number
3. Write a program in Python to check given number is prime or not
Output:
Please enter a number: 7
The given number is a prime number
4.Write a program in Python to print the Fibonacci series using iterative method
Output:
Please enter a number to generate the Fibonacci series: 7
The Fibonacci series is:
0
1
1
2
3
5
8
5. Write a program in Python to print the Fibonacci series using recursive method
Output:
Please enter a number to generate the Fibonacci series: 5
The Fibonacci series is:
0
1
1
2
3
Output: If you enter 535 as the input, the output will be:
Please enter a number: 535
The number is a palindrome
Output:
Please enter a number:12345
num is not binary
10. Write a program in Python to find sum of digits of a number using recursion
Output:
If you enter 10 as the input, the output would be:
Enter a number: 10
Sum of digits of the number is: 1
11. Write a program in Python to swap two numbers without using third variable
Output:
If the input is a=5 and b=7,
After swapping
value of a is : 7
value of b is : 5
12. Write a program in Python to swap two numbers using third variable
Output:
If the input is “10”, “20”, the output will be:
After swapping
value of a is : 20 value of b is : 10
13. Write a program in Python to find prime factors of a given integer
Output:
Enter a number: 20
The prime factors of 20 are: [2, 2, 5]
14. Write a program in Python to add two integer without using arithmetic operator
Output:
Please give first number: 20
Please give second number: 10
Sum = 30;
15. Write a program in Python to find given number is perfect or not?
What is Perfect Number
Output:
please give first number a: 6
given no. is perfect number
please give first number a: 8
given no. is not a perfect number
Output:
Enter the number of elements you want in array: 3
Please give value for index 0:10
Please give value for index 1:20
Please give value for index 2:30
Average of the array elements is 20.0
17. Python Program to calculate factorial using iterative method
Output:
Enter a number: 5
The factorial of 5 is 120
Output:
Enter the number: 6
The factorial of 6 is 720
Output:
Enter the value of n: 5
First 5 prime numbers are: [2, 3, 5, 7, 11]
21. Python Program to print Prime Number in a given range
Example Output:
Enter the first number: 25
Enter the second number: 12
Enter the third number: 36
The smallest number is 12
23. Python program to calculate the power using the POW method
Output:
Enter the base number: 2
Enter the exponent: 3
The result of 2 raised to the power of 3 is 8
24. Python Program to calculate the power without using POW function.(using for loop)
Output:
Enter the value for base : 5
Enter the value for exponent : 4
The result of 5 raised to the power of 4 is 625
25. Python Program to calculate the power without using POW function.(using while loop)
Output:
Enter the value for base : 5
Enter the value for exponent : 4
5 to power of 4 = 625
Output:
Output:
28. Python Program to calculate the square root of a given number
Output 1:
Output 1:
30. Python Program to find GCD or HCF of two numbers
Output :
Output :
32. Python Program to Convert Decimal Number into Binary
Output
100011
Output:
41
34. Python Program to check the given year is a leap year or not
Output:
Enter the number: 1700
Given year is not a leap Year
Output:
Temperature value in degree Celsius: 34
The 34.00 degree Celsius is equal to: 93.20 Fahrenheit
----OR----
Temperature value in degree Celsius: 23
The 23.00 degree Celsius is equal to: 73.40 Fahrenheit
Output 1:
Output :
1. Python program to remove given character from String
Output:
Another method:
Output:
Output :
Output :
7.Python program to check given character is digit or not using isdigit() method
Output :
Output:
end-of-the-day
Python program to print the highest frequency character in a String
Output:
Python program to check given character is digit or not using isdigit() method
Output :
Output:
end-of-the-day
Python program to replace the string space with a given character using replace()
method
Output:
end-of-the-day
Output:
Output:
output:
H-llo World!
Python program to separate characters in a given string
output:
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!']
Output:
example string
Output :
Output:
Python Program to sort characters of string in ascending order
Output 1:
Write a program in Python for, In array 1-100 numbers are stored, one number is
missing how do you find it
Write a program in Python for, In a array 1-100 multiple numbers are duplicates, how
do you find it
Write a program in Python for, How to find all pairs in array of integers whose sum is
equal to given number
Write a program in Python for, How to compare two array is equal in size or not