Write a Python function that takes a number as a parameter and check the number is prime or not.
prime.py
def primeno(num):
flag=0
for i in range(2,num):
if(num%i==0):
flag=1
break
if(flag==1):
print("number is not prime")
else:
print("number is prime")
num=int(input("Enter a number"))
primeno(num)
Output
Question 2
Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument.
factorial.py
def facto(num):
fact=1
for i in range(1,num+1):
fact=fact*i
return fact
num=int(input("Enter a number"))
print("Factorial of number is: ",facto(num))
Output
Question 3
Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters.
countcase.py
def countcase(str1):
count1=0
count2=0
for i in str1:
if(i.islower()):
count1+=1
else:
count2+=1
print("The number of lowercase letters is: ",count1)
print("The number of uppercase letters is: ",count2)
Str=input("Enter a string: ")
print("Count of characters cases:")
countcase(Str)