Write a Python program to find sum of all natural numbers between 1 to n.
Write a Python program to find sum of all natural numbers between 1 to n. SOLUTION…. # Program to find sum of all natural numbers between 1 to n using while loop # Input from user n = int(input(“Enter a number: “)) i = 1 # starting number total = 0 # variable to store […]
Write a Python program to calculate profit or loss.
Write a Python program to calculate profit or loss. SOLUTION…. # Program to calculate Profit or Loss # Input cp = float(input(“Enter Cost Price: “)) sp = float(input(“Enter Selling Price: “)) # Check Profit or Loss if sp > cp: profit = sp – cp print(“Profit = “,profit) elif cp > sp: loss = cp […]
Write a Python program to input week number and print week day
Write a Python program to input week number and print week day SOLUTION…. # Program to print weekday from week number # Input week_num = int(input(“Enter week number (1-7): “)) # Check and print weekday if week_num == 1: print(“Monday”) elif week_num == 2: print(“Tuesday”) elif week_num == 3: print(“Wednesday”) elif week_num == 4: print(“Thursday”) […]
Write a Python program to input electricity unit charges and calculate total electricity bill according to the given condition:
Write a Python program to input electricity unit charges and calculate total electricity bill according to the given condition: SOLUTION…. # Program to calculate Electricity Bill # Input units = float(input(“Enter total electricity units consumed: “)) # Bill calculation if units
Write a Python program to input basic salary of an employee and calculate its Gross salary according to following:
Write a Python program to input basic salary of an employee and calculate its Gross salary according to following: SOLUTION…. # Program to calculate Gross Salary of an Employee # Input basic salary basic = float(input(“Enter basic salary of the employee: “)) # Calculate HRA and DA based on conditions if basic
Write a python program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
Write a python program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: SOLUTION…. # Program to calculate percentage and grade of 5 subjects # Input marks physics = float(input(“Enter marks in Physics: “)) chemistry = float(input(“Enter marks in Chemistry: “)) biology = float(input(“Enter marks […]
Write a python program to input month number and print number of days in that month.
Write a python program to input month number and print number of days in that month. SOLUTION…. # Program to print number of days in a month (Python version) # Input month number month = int(input(“Enter month number (1-12): “)) if month == 1: print(“31 days”) elif month == 2: print(“28 or 29 days”) elif […]
Write a Python program to check whether a number is divisible by 5 and 11 or not.
Write a Python program to check whether a number is divisible by 5 and 11 or not. SOLUTION…. # Program to check divisibility by 5 and 11 # Input num = int(input(“Enter a number: “)) # Check divisibility if num % 5 == 0 and num % 11 == 0: print(“number is divisible by both […]
Write a python program to find maximum between three numbers.
Write a python program to find maximum between three numbers. SOLUTION…. # Program to find maximum among three numbers using if-else # Input a = float(input(“Enter first number: “)) b = float(input(“Enter second number: “)) c = float(input(“Enter third number: “)) # Logic using if-else if a >= b and a >= c: print(“A is […]
Write a Python program to enter radius of a circle and find its diameter, circumference and area.
Write a Python program to enter radius of a circle and find its diameter, circumference and area. SOLUTION…. # Program to calculate diameter, circumference and area of a circle import math # for using pi # Input radius = float(input(“Enter the radius of the circle: “)) # Calculations diameter = 2 * radius circumference = […]
