0% found this document useful (0 votes)
155 views

Python Program To Check Prime Number

The document contains code snippets for: 1) A Python program to check if a number is prime or not. 2) Programs to convert between ASCII and characters, and get the ASCII value of a character. 3) A program that checks if a given input character is an alphabet, number or special character. 4) A program to search if a given word is present in a string/sentence. 5) A description for a program that performs all arithmetic operations on two input numbers in a function.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views

Python Program To Check Prime Number

The document contains code snippets for: 1) A Python program to check if a number is prime or not. 2) Programs to convert between ASCII and characters, and get the ASCII value of a character. 3) A program that checks if a given input character is an alphabet, number or special character. 4) A program to search if a given word is present in a string/sentence. 5) A description for a program that performs all arithmetic operations on two input numbers in a function.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like