Uploaded by Yash K

PYTHON assignment

advertisement
BRACT’s
Vishwakarma Institute of Information Technology, Pune
Department: IT
Semester: II
Academic Year: 2023-24
Assignment No: 1
Class/ Division/ Batch: FY-B3
Roll no:69
Course Name: Python Programming
Name of Student: Yash Kamlesh Kataria
Programs:
1) To Print Hello world!
Code: print("Hello, World!")
Output:
2) Program to Add Two Numbers.
Code:
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
c=a+b
print(f"The sum of {a} and {b} is: {c}")
Output:
3) Program to perform arithmetic operations on two numbers.
Code:
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
sum result = a + b
difference result = a - b
product result = a * b
quotient result = a / b
print(f"Sum: {a} + {b} = {sum result}")
Group no: -
print(f"Difference: {a} - {b} = {difference result}")
print(f"Product: {a} * {b} = {product result}")
print(f"Quotient: {a} / {b} = {quotient result}")
Output:
4) Program to Generate a Random Number.
Code:
import random
random_number = random.randint(1, 100)
print(f"Random Number: {random_number}")
Output:
5) Program to Convert Kilometers to Miles.
Code:
kilometers = float(input("Enter distance in kilometers: "))
conversion_factor = 0.621371
miles = kilometers * conversion_factor
print(f"{kilometers} kilometers is equal to {miles} miles")
Output:
Conclusion: In this way we have studied and completed Assignment 1.
Remark:
Name of Faculty:
Ms. Riddhi R Mirajkar
Sign:
BRACT’s
Vishwakarma Institute of Information Technology, Pune
Department: IT
Semester: II
Academic Year: 2023-24
Assignment No: 2
Class/ Division/ Batch: FY-B3
Roll no:69
Course Name: Python Programming
Name of Student: Yash Kamlesh Kataria
Programs:
1) Program to find maximum of two numbers.
Code:
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
maximum number = max(a, b)
print(f"The maximum of {a} and {b} is: {maximum number}")
Output:
2) Program to check if a number is even or odd.
Code:
number = int(input("Enter a number: "))
if number % 2 == 0:
print(f"{number} is an even number.")
else:
print(f"{number} is an odd number.")
Output:
Group no: -
3) Program to check if a year is leap.
Code:
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
Output:
4) Program to check if a date is valid.
Code:
def is_leap_year(year):
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
def is_valid_date(day, month, year):
max_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if is_leap_year(year):
max_days[2] = 29
if 1 <= month <= 12 and 1 <= day <= max_days[month] and year > 0:
return True
else:
return False
day = int(input("Enter day: "))
month = int(input("Enter month: "))
year = int(input("Enter year: "))
if is_valid_date(day, month, year):
print(f"The date {day}/{month}/{year} is valid.")
else:
print(f"The date {day}/{month}/{year} is not valid.")
Output:
5) Program to find the roots of a quadratic equation.
Code:
import math
a = float(input("Enter the coefficient a: "))
b = float(input("Enter the coefficient b: "))
c = float(input("Enter the coefficient c: "))
d = b**2 - 4*a*c
if d >= 0:
root1 = (-b + math.sqrt(d)) / (2*a)
root2 = (-b - math.sqrt(d)) / (2*a)
print(f"The roots of the quadratic equation are: {root1} and {root2}")
else:
print("The quadratic equation has complex roots.")
Output:
Conclusion: In this way we have studied and completed Assignment 2.
Remark:
Name of Faculty:
Ms. Riddhi R Mirajkar
Sign:
Download