Prime Number
                                


num = int(input("Enter Number"))


if num > 1:
   
   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")
    
else:
   print(num,"is not a prime number")

Prime Number Given Range




Startnum = int(input("Enter Start Number"))
Endnum = int(input("Enter  End Number"))

print("Prime numbers between",Startnum,"and",Endnum,"are:")

for num in range(Startnum,Endnum + 1):
   if num > 1:
       for i in range(2,num):
           if (num % i) == 0:
               break
       else:
           print(num)


Program to check Armstrong numbers in certain interval






lower = int(input("Enter Staring Value"))
upper = int(input("Enter Ending Value"))



for num in range(lower, upper + 1):

   # order of number
   order = len(str(num))
   sum = 0
   # find the sum of the cube of each digit
   temp = num
   while temp > 0:
       digit = temp % 10
       sum += digit ** order
       temp //= 10

   if num == sum:
       print(num)


Check Armstrong number of n digits



num = int(input("Enter Number"))

order = len(str(num))

# initialize sum
sum = 0

# find the sum of the cube of each digit
temp = num
while temp > 0:
   digit = temp % 10
   sum += digit ** order
   temp //= 10
if num == sum:
   print(num,"is an Armstrong number")
else:
   print(num,"is not an Armstrong number")



Python program to find the factorial of a number using recursion




def factorial(n):
   if n == 1:
       return n
   else:
       return n*factorial(n-1)

num =int(input("Enter Number"))


if num < 0:
   print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
   print("The factorial of 0 is 1")
else:
   print("The factorial of",num,"is",factorial(num))

Python Program to print Palindrome numbers from 1 to 100





 
maximum = int(input(" Please Enter the Maximum Value : "))
minimum=1
print("Palindrome Numbers between %d and %d are : " %(minimum, maximum))
for num in range(minimum, maximum + 1):
    temp = num
    reverse = 0
    
    while(temp > 0):
        Reminder = temp % 10
        reverse = (reverse * 10) + Reminder
        temp = temp //10

    if(num == reverse):
        print("%d " %num, end = ' ')

Reverse number using Recursion



num = int(input("Please Enter any Number: "))
Reverse = 0
while(num > 0):
    Reminder = num %10
    Reverse = (Reverse *10) + Reminder
    num = num //10

print("Reverse of entered number is = %d" %Reverse)

Fibonacci Series


nterms = 100
n1 = 0
n2 = 1
count = 0

if nterms <= 0:
   print("Please enter a positive integer")
elif nterms == 1:
   print("Fibonacci sequence upto",nterms,":")
   print(n1)
else:
   print("Fibonacci sequence upto",nterms,":")
   while count < nterms:
       print(n1,end=' , ')
       nth = n1 + n2
       # update values
       n1 = n2
       n2 = nth
       count += 1

Find ASCII value of a Character

c =input("Enter Character")
print("The ASCII value of '" + c + "' is",ord(c))


Leap Year
                                
year = int(input("Enter Year"))

if (year % 4) == 0:
   if (year % 100) == 0:
       if (year % 400) == 0:
           print("{0} is a leap year".format(year))
       else:
           print("{0} is not a leap year".format(year))
   else:
       print("{0} is a leap year".format(year))
else:
   print("{0} is not a leap year".format(year))


Convert a string to uppercase

string = "Msk Tutorials!"
print(string.upper())

Convert a string to lowercase

string = "Msk Tutorials!"
print(string.lower())


Count Number of Digits in an Integer

count = 0
number = int(input("Enter a number "))
while (number > 0):
  number = number//10
  count = count + 1
print ("Total number of digits : ",count)


Check Whether a Character is an Alphabet or not


ch = input("Enter any character: ");

if ch == '0':
    print("You Enter '0'.");
    exit();
else:
    if((ch>='a' and ch<='z') or (ch>='A' and ch<='Z')):
    	print(ch, "is an alphabet.");
    else:
    	print(ch, "is not an alphabet.");

Get radio button value (selected radio button)

string=input("Enter string:")
vowels=0
for i in string:
      if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):
            vowels=vowels+1
print("Number of vowels are:",)
print(vowels)

Number Of Vowels In the given String

string=input("Enter string:")
vowels=0
for i in string:
      if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):
            vowels=vowels+1
print("Number of vowels are:",)
print(vowels)


Add a SpinBox (numbers widget)

from tkinter import *
 
top = Tk()
 
top.title("Welcome to Msk Tutorials")
 
top.geometry('350x200')
 
spin = Spinbox(top, from_=0, to=100, width=5)
 
spin.grid(column=0,row=0)
 
top.mainloop()

Remove Duplicates from a List

def Remove(duplicate): 
    final_list = [] 
    for num in duplicate: 
        if num not in final_list: 
            final_list.append(num) 
    return final_list 
      
# Driver Code 
duplicate = [2, 4, 10, 20, 5, 2, 20, 4,24,25,24] 
print(Remove(duplicate)) 

Python Program to Replace all Occurrences of ‘a’ with $ in a String

string=raw_input("Enter string:")
string=string.replace('a','$')
string=string.replace('A','$')
print("Modified string:")
print(string)