0% found this document useful (0 votes)
11 views4 pages

Assignment No.1 - Colab

The document contains a series of Python programming exercises that cover various topics such as user input, arithmetic operations, character classification, geometry calculations, and conditionals. Each question includes code snippets that demonstrate how to implement the required functionality, along with example outputs. The exercises range from basic tasks like checking if a number is positive or negative to more complex calculations like the area and cost of a triangle.

Uploaded by

samukunchatwar21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Assignment No.1 - Colab

The document contains a series of Python programming exercises that cover various topics such as user input, arithmetic operations, character classification, geometry calculations, and conditionals. Each question includes code snippets that demonstrate how to implement the required functionality, along with example outputs. The exercises range from basic tasks like checking if a number is positive or negative to more complex calculations like the area and cost of a triangle.

Uploaded by

samukunchatwar21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Que.

1] For asking user to answer Yes or No to a question such as " Are you ready to provide
youre credit card number? (1=Yes/0=No)"

ans = input("Are you ready to provide youre credit card number? (1=Yes/0=No):")
print("Your choice:",ans)
if (ans == '1'):
print("We will Continue the processing of transaction")
elif (ans == '0'):
print("We will Not Continue the processing of transaction")

Are you ready to provide youre credit card number? (1=Yes/0=No):1


Your choice: 1
We will Continue the processing of transaction

Que.2] Write a program to enter two numbers and print their diference.

a = int(input("Enter the first number:"))


b = int(input("Enter the second number:"))
diff = a-b
print("First number is:",a)
print("Second number is:",b)
print("Difference between two numbers is:",diff)

Enter the first number:47


Enter the second number:95
First number is: 47
Second number is: 95
Difference between two numbers is: -48

Que.3] Write a program to swap values of two variables.

x=int(input("Enter the first number:"))


y=int(input("Enter the second number:"))
temp=x
x=y
y=temp
print("Value of x after swapping:",x)
print("Value of y after swapping:",y)

Enter the first number:7


Enter the second number:20
Value of x after swapping: 20
Value of y after swapping: 7

Que. 4] To enter a character and print whether a given character is an alphabet, digit or any
character.

ch = input("Please Enter Character : ")


if ((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
elif (ch >= '0' and ch <= '9'):
print("The Given Character ", ch, "is an Digit")
else:
print("The Given Character ", ch, "is other than Alphabets and Digits")

Please Enter Character : s


The Given Character s is an Alphabet

Que. 5] Write a program to obtain length,breadth and height of a cuboid and calculate its
volume. Note: Formula:- volume = lbh

l = int(input("Enter the length of cuboid:"))


b = int(input("Enter the breadth of cuboid:"))
h = int(input("Enter the height of cuboid:"))
volume = l*b*h
print("Length of cuboid is:",l)
print("Breadth of cuboid is:",b)
print("Height of cuboid is:",h)
print("Volume of cuboid is:",volume)

Enter the length of cuboid:5


Enter the breadth of cuboid:5
Enter the height of cuboid:5
Length of cuboid is: 5
Breadth of cuboid is: 5
Height of cuboid is: 5
Volume of cuboid is: 125

Que.6]Write a python program which inputs three sides of triangle and calculate its
perimeter,semi perimeter and area. Note: Formula:- Perimeter = a+b+c , semi perimeter :- s =
(a+b+c)/2 , area= (s(s-a)(s-b)(s-c))*0.5

a= float(input("Enter the first side of triangle:"))


b= float(input("Enter the second side of triangle:"))
c= float(input("Enter the third side of triangle:"))
#calculate the perimeter
Perimeter = a+b+c
#calculate the semi perimeter
s= (a+b+c)/2
#calculate the area
area= (s*(s-a)*(s-b)*(s-c))**0.5
print("First side of triangle is:",a)
print("Second side of triangle is:",b)
print("Third side of triangle is:",c)
print("Perimeter of triangle is:",Perimeter)
print("Semi perimeter of triangle is:",s)
print("Area of triangle is:",area)

Enter the first side of triangle:4


Enter the second side of triangle:4
Enter the third side of triangle:2
First side of triangle is: 4.0
Second side of triangle is: 4.0
Third side of triangle is: 2.0
Perimeter of triangle is: 10.0
Semi perimeter of triangle is: 5.0
Area of triangle is: 3.872983346207417
Que.7] Write a python program which calculate the cost of triangle area wise. Also display its
output.

a= float(input("Enter the first side of triangle:"))


b= float(input("Enter the second side of triangle:"))
c= float(input("Enter the third side of triangle:"))
#calculate the semi perimeter
s= (a+b+c)/2
#calculate the area
area= (s*(s-a)*(s-b)*(s-c))**0.5
print("First side of triangle is:",a)
print("Second side of triangle is:",b)
print("Third side of triangle is:",c)
print("Area of triangle is:",area)
cost = float (input("Enter the cost per meter square in rs:"))
print("Cost of triangle area is:",cost)
Total_Cost = area*cost
print("Total cost of triangle area is:",Total_Cost)

Enter the first side of triangle:12


Enter the second side of triangle:13
Enter the third side of triangle:5
First side of triangle is: 12.0
Second side of triangle is: 13.0
Third side of triangle is: 5.0
Area of triangle is: 30.0
Enter the cost per meter square in rs:15.50
Cost of triangle area is: 15.5
Total cost of triangle area is: 465.0

Que. 8] Write a Python Program to Check if a Number is Positive, Negative or 0

num = float(input("Enter a number: "))


if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

Enter a number: -8
Negative number

Que. 9] Write a Python Program to covert the centimeter value into meter and kilometer.

cm = float(input("Enter the length in centimeters: "))


# Conversion calculations
meters = cm / 100 # 1 meter = 100 cm
kilometers = cm / 100000 # 1 kilometer = 100,000 cm
# Display the results
print(f"\nLength in meters: {meters} m")
print(f"Length in kilometers: {kilometers} km")

Enter the length in centimeters: 5000

Length in meters: 50.0 m


Length in kilometers: 0.05 km

Que. 10] Write a python program to Check Leap Year. Note:- A leap year is exactly divisible by 4
except for century years (years ending with 00). The century year is a leap year only if it is
perfectly divisible by 400.

# To get year (integer input) from the user


year = int(input("Enter a year: "))
# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
print("{0} is a leap year".format(year))
# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
print("{0} is a leap year".format(year))
# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
print("{0} is not a leap year".format(year))

Enter a year: 2024


2024 is a leap year

You might also like