Q1 - Swap The Values of Two Variables A and B - Q2-wr...
Q1 - Swap The Values of Two Variables A and B - Q2-wr...
print("a =", a)
print("b =", b)
Output:
a = 20
b = 10
Explanation: The a, b = b, a syntax simultaneously assigns the value of b to a and the value of
a to b, effectively swapping their values.
Q2: Write a Python code to convert the time given in minutes into hours and minutes.
total_minutes = 150
hours = total_minutes // 60
minutes = total_minutes % 60
print("Hours:", hours)
print("Minutes:", minutes)
Output:
Hours: 2
Minutes: 30
Explanation: The // operator performs integer division, giving the number of whole hours. The
% operator calculates the remainder, giving the remaining minutes.
Q3: Write a program that asks the user for the year and prints whether it is a leap year or
not.
year = int(input("Enter a year: "))
Explanation: A leap year is divisible by 4, but not by 100 unless it's also divisible by 400. The
code checks these conditions using the % operator for divisibility.
Q4: Write a program to obtain temperature in Celsius and convert it into Fahrenheit using
the formula C*9/5+32
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
Explanation: The code calculates the year of birth by subtracting the age from the current year.
Then, it adds 100 to the year of birth to find the year when the user will turn 100.
Q6: Write a program to get selling price and GST rate, and print an invoice along with
both GST and SGST.
selling_price = float(input("Enter selling price: "))
gst_rate = float(input("Enter GST rate: "))
cgst_rate = gst_rate / 2
sgst_rate = gst_rate / 2
print("Invoice")
print("Selling Price:", selling_price)
print("CGST Rate:", cgst_rate, "%")
print("CGST Amount:", cgst_amount)
print("SGST Rate:", sgst_rate, "%")
print("SGST Amount:", sgst_amount)
print("Total GST:", total_gst)
print("Total Amount:", total_amount)
Explanation: The code calculates the CGST and SGST amounts based on the selling price and
GST rate. It then calculates the total GST and total amount.
Q7: Write a Python code to calculate and display the selling price of an item, cost price,
and profit to be accepted by the user.
cost_price = float(input("Enter cost price: "))
profit_percentage = float(input("Enter profit percentage: "))
Explanation: The code calculates the profit based on the cost price and profit percentage, and
then calculates the selling price by adding the profit to the cost price.
Q8: Write a Python program to accept marks in 5 subjects and outputs total and average
marks.
subject1 = float(input("Enter marks in Subject 1: "))
subject2 = float(input("Enter marks in Subject 2: "))
subject3 = float(input("Enter marks in Subject 3: "))
subject4 = float(input("Enter marks in Subject 4: "))
subject5 = float(input("Enter marks in Subject 5: "))
Explanation: The code takes input for marks in 5 subjects, calculates the total marks and
average marks, and prints the results.
Q9: Write a program to input a number and print its first five multiples.
number = int(input("Enter a number: "))
Explanation: The code uses a for loop to iterate from 1 to 5, multiplying the input number by
each iteration and printing the result.
Q10: Write a program to find the area of a triangle.
base = float(input("Enter base of the triangle: "))
height = float(input("Enter height of the triangle: "))
Explanation: The formula (base * height) / 2 is used to calculate the area of a triangle.
● https://edurev.in/t/268072/Assignment-Python-Variables-Data-Types
● https://github.com/Aashrya123/assignment