Python Program of Basic Questions (Part-1)
The following Python section contains a wide collection of Basic Python programming examples. This is Python Program of Basic Questions (Part-1) , another part-2 is in another section.
Q1. Write a python program to Swap Two Number.
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
a, b= b, a
print("Value of a=", a)
print("Value of b=", b)
Output:
Enter the value of a:10
Enter the value of b:20
Value of a= 20
Value of b= 10
Q2. Swap two numbers by using Bitwise operator in python.
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
a = a ^ b;
b = a ^ b;
a = a ^ b;
print("Value of a = ", a, " Value of b =", b)
Output:
Enter the value of a:22
Enter the value of b:44
Value of a = 44
Value of b = 22
Q3. Write a python program to convert temperature from Celsius to Fahrenheit.
Celsius = float(input("Enter temperature in Celsius: "))
Fahrenheit = (Celsius * 9/5) + 32
print( "Temperature in Fahrenheit=",Fahrenheit)
Output:
Enter temperature in Celsius: 0
Temperature in Fahrenheit= 32.0
Q4. Write a python program to convert specified days into years, weeks and days. (Example :> 500 Days = 1 year, 19 weeks and 2 days).
days=int(input("Enter Day:"))
years =int( (days / 365))
weeks = int((days % 365) / 7)
days = int(days - ((years * 365) + (weeks * 7)))
print(years, "Years")
print(weeks, "Weeks")
print(days, "Days")
Output:
Enter Day:410
1 Years
6 Weeks
3 Days
Q5. Write a python program that accepts an employee’s ID, total worked hours of a month and the amount he received per hour. Print the employee’s ID and salary of a particular month.
emp_name= str(input("Enter Employees Name : "))
emp_id= int(input("Enter Employees ID : "))
working_hrs=int(input("Enter Working Hours : "))
rate=int(input("Enter Rate of Employees per Hrs: "))
print("\n"*5)
amount=(working_hrs*rate)
print("Employee Name : ",emp_name)
print("Employee ID : ",emp_id)
print("Total Hours : ",working_hrs)
print("Rate Per Hrs : RS ",rate)
print("Employee Salary is : RS ",amount)
Output:
Enter Employees Name : chilled coder
Enter Employees ID : 2020
Enter Working Hours : 500
Enter Rate of Employees per Hrs: 5000
Employee Name : chilled coder
Employee ID : 2020 Total Hours : 500
Rate Per Hrs : RS 5000
Employee Salary is : RS 2500000
Q6. Write a python program to convert a given number (in seconds) to hours, minutes and seconds.(Example :> 10000 Seconds = 2 Hrs., 46 Mins, 40 Sec.
sec=int(input("Enter Seconds : "))
hours=int( (sec / 3600))
minutes = int((sec % 3600) / 60)
second = int(sec - ((hours * 3600) + (minutes * 60)))
print(hours, "Hours")
print(minutes, "Minutes")
print(second, "Seconds")
Output:
Enter Seconds : 55555
15 Hours
25 Minutes
55 Seconds
Q7. Write a python program to calculate Compound Interest. Take amount, time and rate as input values from the user and calculate compound interest.
pri=int(input("Enter Principle Amount : "))
rate=int(input("Enter Interest Rate : "))
time=int(input("Enter time in yrs : "))
def interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print("Compound interest is", CI)
interest(pri,rate, time)
Output:
Enter Principle Amount : 500
Enter Interest Rate : 66600
Enter time in yrs : 10
Compound interest is 8.714216458987011e+30
Q8 . Calculate the distance between the two points. Take x –coordinates and y-coordinates of two points from the user and find out the difference.
import math
x1=int(input("Enter X Coordinates of Point A : "))
y1=int(input("Enter Y Coordinates of Point A : "))
x2=int(input("Enter X Coordinates of Point B : "))
y2=int(input("Enter Y Coordinates of Point B : "))
distance = math.sqrt( ((x2-x1)*2)+((y2-y1)*2) )
print("Distance between point A and B = ", distance)
Output:
Enter X Coordinates of Point A : 5
Enter Y Coordinates of Point A : 5
Enter X Coordinates of Point B : 9
Enter Y Coordinates of Point B : 9
Distance between point A and B = 4.0
I Think You Understand above Topic “ Python Program of Basic Questions (Part-1) ”.
For any query or suggestions feel free to fill comment section and send it.
More Topic of Python:
Python Program of Basic Question’s Part-2
Top Python Program of String for beginner
Mind Blowing While Loop program for beginner
Recent Comments