
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

3K+ Views
When it is required to read the height in ‘cm’ and convert it into ‘feet’ and ‘inches’, the ‘round’ method can be used.Below is a demonstration of the same −Example Live Demoin_cm=int(input("Enter the height in centimeters...")) in_inches=0.394*in_cm in_feet=0.0328*in_cm print("The length in inches is ") print(round(in_inches, 2)) print("The length in feet is") print(round(in_feet, 2))OutputEnter the height in centimeters...178 The length in inches is 70.13 The length in feet is 5.84ExplanationThe input is taken by user, as ‘cm’.It can be converted into inches by multiplying it with 0.394.This is assigned to a variable.It can be converted into feet by multiplying it with 0.0328.This ... Read More

334 Views
When it is required to compute a simple interest when the amount, rate and interest are given, a simple formula can be defined, and the elements can be plugged into the formula.Below is a demonstration of the same −Example Live Demoprinciple_amt = float(input("Enter the principle amount...")) my_time = int(input("Enter the time in years...")) my_rate = float(input("Enter the rate...")) my_simple_interest=(principle_amt*my_time*my_rate)/100 print("The computed simple interest is :") print(my_simple_interest)OutputEnter the principle amount...45000 Enter the time in years...3 Enter the rate...6 The computed simple interest is : 8100.0ExplanationThe principal amount, the rate of interest, and the time are taken as user inputs.Another formula is defined ... Read More

581 Views
When it is required to check if a date is valid or not, and print the incremented date if it is a valid date, the ‘if’ condition is used.Below is a demonstration of the same −Example Live Demomy_date = input("Enter a date : ") dd, mm, yy = my_date.split('/') dd=int(dd) mm=int(mm) yy=int(yy) if(mm==1 or mm==3 or mm==5 or mm==7 or mm==8 or mm==10 or mm==12): max_val = 31 elif(mm==4 or mm==6 or mm==9 or mm==11): max_val = 30 elif(yy%4==0 and yy%100!=0 or yy%400==0): max_val = 29 else: max_val = 28 if(mm12 or dd max_val): print("The date ... Read More

419 Views
When it is required to read a number and print the pattern of summation of natural numbers, a simple ‘for’ loop can be used.Below is a demonstration of the same −Example Live Demomy_num = int(input("Enter a number... ")) for j in range(1,my_num+1): my_list=[] for i in range(1,j+1): print(i,sep=" ",end=" ") if(i

391 Views
When it is required to display the sum all the natural numbers within a given range, a method can be defined that uses a loop to iterate over the elements, and returns the sum of these numbers as output.Below is a demonstration of the same −Example Live Demodef sum_natural_nums(val): my_sum = 0 for i in range(1, val + 1): my_sum += i * (i + 1) / 2 return my_sum val = 9 print("The value is ") print(val) print("The sum of natural numbers upto 9 is : ") print(sum_natural_nums(val))OutputThe value is 9 The sum ... Read More

2K+ Views
When it is required to print all the elements which can’t be divided by 2 or 3 and lie between 1 and 50, the constraints are mentioned in the form of a ‘while’ loop and ‘if’ condition.Below is a demonstration of the same −Example Live Demoprint("Integers not divisible by 2 and 3, that lie between 1 and 50 are : ") n = 1 while n

3K+ Views
When it is required to find the smallest divisor of a an integer, a simple ‘for’ loop is used.Below is a demonstration of the same −Example Live Demofirst_num = int(input("Enter a number...")) my_list = [] print("The number is ") print(first_num) for i in range(2, first_num+1): if(first_num%i==0): my_list.append(i) my_list.sort() print("The smallest divisor is : ") print(my_list[0])OutputEnter a number...56 The number is 56 The smallest divisor is : 2ExplanationThe number is taken as an input from the user.An empty list is defined.The number taken from user is displayed on the console.The number range is iterated over.It is ... Read More

2K+ Views
When it is required to print all possible combination of digits when the input is taken from the user, nested loop is used.Below is a demonstration of the same −Example Live Demofirst_num = int(input("Enter the first number...")) second_num = int(input("Enter the second number...")) third_num = int(input("Enter the third number...")) my_list = [] print("The first number is ") print(first_num) print("The second number is ") print(second_num) print("The third number is ") print(third_num) my_list.append(first_num) my_list.append(second_num) my_list.append(third_num) for i in range(0, 3): for j in range(0, 3): for k in range(0, 3): if(i!=j&j!=k&k!=i): ... Read More

2K+ Views
When it is required to read two numbers and print the quotient and remainder when they are divided, the ‘//’ and ‘%’ operators can be used.Below is a demonstration of the same −Example Live Demofirst_num = int(input("Enter the first number...")) second_num = int(input("Enter the second number...")) print("The first number is ") print(first_num) print("The second number is ") print(second_num) quotient_val = first_num//second_num remainder_val = first_num%second_num print("The quotient is :") print(quotient_val) print("The remainder is :") print(remainder_val)OutputEnter the first number...44 Enter the second number...56 The first number is 44 The second number is 56 The quotient is : 0 The remainder is : ... Read More

2K+ Views
When it is required to print all the elements in a given range that is divisible by a specific number, a simple for loop can be used.Below is a demonstration of the same −Example Live Demolower_num = int(input("Enter lower range limit...")) upper_num = int(input("Enter upper range limit...")) div_num = int(input("Enter the number that should be divided by...")) for i in range(lower_num, upper_num+1): if(i%div_num==0): print(i)OutputEnter lower range limit...3 Enter upper range limit...8 Enter the number that should be divided by...2 4 6 8ExplanationThe upper and lower range of numbers is taken as input from the user.The number by ... Read More