Python programs

Python Program to Find Armstrong Number between an Interval

We have already read the concept of Armstrong numbers in the previous program. Here, we print the Armstrong numbers within a specific given interval.

See this example:

  1. lower = int(input(“Enter lower range: “))  
  2. upper = int(input(“Enter upper range: “))  
  3.   
  4. for num in range(lower,upper + 1):  
  5.    sum = 0  
  6.    temp = num  
  7.    while temp > 0:  
  8.        digit = temp % 10  
  9.        sum += digit ** 3  
  10.        temp //= 10  
  11.        if num == sum:  
  12.             print(num)  

This example shows all Armstrong numbers between 100 and 500.

null

Output:

Python Condition And Loops11

Python program to display calender

Python program to display calendar
It is simple in python programming to display calendar. To do so, you need to import the calendar module which comes with Python.

  1. import calendar  
  2.  And then apply the syntax  
  3. (calendar.month(yy,mm))  

See this example:

  1. import calendar  
  2. # Enter the month and year  
  3. yy = int(input(“Enter year: “))  
  4. mm = int(input(“Enter month: “))  
  5.   
  6. # display the calendar  
  7. print(calendar.month(yy,mm))  

Output:

Python Basic Programs10
Design a site like this with WordPress.com
Get started