Problem StatementCharlie is intrigued by the concept of prime ASCII codes. Write a program to help Charlie determine whether a given character corresponds to a prime ASCII code. Check if the ASCII code is a prime number and print "yes" if it is prime and "no" otherwise.Assist Charlie in developing a program that accurately identifies prime ASCII codes for different characters.Input format :The input consists of a character c.Output format :The output prints "yes" if the converted ASCII code is a prime number, and "no" if it is not a prime number.
Question
Problem StatementCharlie is intrigued by the concept of prime ASCII codes. Write a program to help Charlie determine whether a given character corresponds to a prime ASCII code. Check if the ASCII code is a prime number and print "yes" if it is prime and "no" otherwise.Assist Charlie in developing a program that accurately identifies prime ASCII codes for different characters.Input format :The input consists of a character c.Output format :The output prints "yes" if the converted ASCII code is a prime number, and "no" if it is not a prime number.
Solution
Sure, here is a Python solution for the problem:
def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
i = 3
while i * i <= n:
if n % i:
i += 2
else:
return False
return True
def check_prime_ascii(c):
ascii_val = ord(c)
if is_prime(ascii_val):
return "yes"
else:
Similar Questions
Complete the code to find if a given number is a prime number? The program will take a positive integer greater than 1 as input and indicate if it is a prime number by saying "prime", and if it is not a prime number saying "not a prime". Note there are 3 places in the given code that you need to fix for this code to work properly and give the expected output.
write easies code for me : Write a program in C to find if a number is prime or not.
What are looping statements. Write a program to check whether a number is prime no. or not.
An integer value N is passed as the input. The program must print YES if N is prime number. Else the program must print NO.Input Format:The first line denotes the value of N.Output Format:YES or NO based on if N is a prime number or not. (The OUTPUT is CASE SENSITIVE).Boundary Conditions:2 <= N <= 9999999Example Input/Output 1:Input:19Output:YESExample Input/Output 2:Input:189210Output:NO
Write a program primes.py that reads a positive integer from standard input, and determines whether or not the number is prime.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.