- Program to Check whether Year is a Leap Year or not
- Program to Check Vowel or Consonant
- Program To Add Two Binary Numbers
- Program To Add Two Numbers
- Program to Check If a number is Prime or not
- Program to Check If number is Even or Odd
- Program to Find Factorial of Number
- Program to Calculate length of a String

In [1]:

```
# User enters the year
year = int(input("Enter Year: "))
# Leap Year Check
if year % 4 == 0 and year % 100 != 0:
print(year, "is a Leap Year")
elif year % 100 == 0:
print(year, "is not a Leap Year")
elif year % 400 ==0:
print(year, "is a Leap Year")
else:
print(year, "is not a Leap Year")
```

In this program, user is asked to enter a character and the input character is stored in a variable. The program checks whether the entered character lies in the range of lowercase or uppercase alphabets, if it does then the program displays the message that the “character is an Alphabet” else it displays that the “character is not an Alphabet”.

In [4]:

```
# taking user input
ch = input("Enter a character: ")
if((ch>='a' and ch<= 'z') or (ch>='A' and ch<='Z')):
print(ch, "is an Alphabet")
else:
print(ch, "is not an Alphabet")
```

In [3]:

```
# taking user input
ch = input("Enter a character: ")
if(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I'
or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u'):
print(ch, "is a Vowel")
else:
print(ch, "is a Consonant")
```

In [5]:

```
# decimal value 1
num1 = '00001'
# decimal value 17
num2 = '10001'
# sum - decimal value 18
# binary value 10010
sum = bin(int(num1,2) + int(num2,2))
print(sum)
```

You can even ask the user to input the values. For that you would have to make use of input() build-in function.

Method:1

In [7]:

```
# two float values
val1 = 100.99
val2 = 76.15
# Adding the two given numbers
sum = float(val1) + float(val2)
# Displaying the addition result
print("The sum of given numbers is: ", sum)
```

Method 2:

In [8]:

```
# Getting the values of two numbers from user
val1 = float(input("Enter first number: "))
val2 = float(input("Enter second number: "))
# Adding the numbers
sum = val1 + val2
# Displaying the result
print("The sum of input numbers is: ", sum)
```

In [9]:

```
# taking input from user
number = int(input("Enter any number: "))
# prime number is always greater than 1
if number > 1:
for i in range(2, number):
if (number % i) == 0:
print(number, "is not a prime number")
break
else:
print(number, "is a prime number")
# if the entered number is less than or equal to 1
# then it is not prime number
else:
print(number, "is not a prime number")
```

In [10]:

```
num = int(input("Enter any number: "))
flag = num%2
if flag == 0:
print(num, "is an even number")
elif flag == 1:
print(num, "is an odd number")
else:
print("Error, Invalid input")
```

**Concept Of Factorial**

Factorial of a number is the product of an integer and all the integers below it, for example the factorial of 4 is 4*3*2*1 = 24. Her we will be making use of the python function factorial(). The function will calculate the factorial abd then display.

In [12]:

```
def factorial(num):
"""This is a recursive function that calls
itself to find the factorial of given number"""
if num == 1:
return num
else:
return num * factorial(num - 1)
# We will find the factorial of this number
num = int(input("Enter a Number: "))
# if input number is negative then return an error message
# elif the input number is 0 then display 1 as output
# else calculate the factorial by calling the user defined function
if num < 0:
print("Factorial cannot be found for negative numbers")
elif num == 0:
print("Factorial of 0 is 1")
else:
print("Factorial of", num, "is: ", factorial(num))
```

In [11]:

```
# User inputs the string and it gets stored in variable str
str = input("Enter a string: ")
# counter variable to count the character in a string
counter = 0
for s in str:
counter = counter+1
print("Length of the input string is:", counter)
```

**Thank You** for visiting our website. If you like our work, please support us so that we can keep on creating new tutorials/blogs on interesting topics (like AI, ML, Data Science, Python, Digital Marketing, SEO, etc.) that can help people learn new things faster. You can support us by clicking on the **Coffee** button at the bottom right corner. We would appreciate even if you can give a thumbs-up to our article in the comments section below.

If you want to

- provide some suggestions on topic
- share your views
- include some details in tutorial
- suggest some new topics on which we should create tutorials/blogs