Ch-3- Advance Python (Answer)
Ch-3- Advance Python (Answer)
ASSIGNMENT – 1
TITLE - CONTROL STATEMENTS IN PYTHON
-------------------------------------------------------------------------------------------------------------------------
Write Python codes for the following questions along with the output.
Q1. Write a Python program that takes three numbers as input and then calculates and prints both their
sum and average.
Ans.
avg = sum / 3
OUTPUT
Q2. Write a Python program that accepts the length and breadth of a rectangle in centimetres and
calculates and prints both its area and perimeter.
list2 = input("Enter 2nd list items = ") Enter 1st list items = [34,67,90]
Q4. WAP to display the first three elements of a list. Assuming the list is [56,80,43,7.8,5.3,'M','H','KTS']
Q5. Create a program that takes the cost price and the selling price of an item, checks whether a profit
was gained or a loss was incurred, and then prints the amount of profit or loss. Provide the output for at
least two sample cases.
else:
Q7. Write a program that calculates and prints the sum of the first ten natural numbers.
sum = 0 OUTPUT
sum = sum + i
i = i+1
Q8. Create a program (WAP) that prints each character of a given string in reverse order. Assume the input
string is "INDIA."
x = "INDIA" OUTPUT
print(i) I