1.
python program to check prime number
#num = 407
# To take input from the user
num = int(input("Enter a number: "))
if num == 1:
print(num, "is not a prime number")
elif num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
2. python program to convert character to asci and vice versa
# Python program to convert ASCII to character
# take input
num = int(input("Enter ASCII value: "))
# printing character
print("Character =", chr(num))
# Python program to print
# ASCII Value of Character
# In c we can assign different
# characters of which we want ASCII value
#c = 'g'
c=input("Enter a Character: ")
# print the ASCII value of assigned character in c
print("The ASCII value of '" + c + "' is", ord(c))
3. input a number and to print whether given character is an alphabet
# Python Program to check whether the given input is alphabet, number or special character
ch = input("Please Enter Any Character : ")
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
elif(ch >= '0' and ch <= '9'):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is a Special Character")
4. pgm to search any word in given string /sentence
# Python3 implementation of the approach
# Function that returns true if the word is found
def isWordPresent(sentence, word):
# To break the sentence in words
s = sentence.split(" ")
for i in s:
# Comparing the current word
# with the word to be searched
if (i == word):
return True
return False
# Driver code
s = "Geeks for Geeks"
word = "Geeks"
if (isWordPresent(s, word)):
print("Yes")
else:
print("No")
5. pgm that receives two numbers in a function and return the result of all arithematic operations
on these numbers.
6.