Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Capsule 2:Durgesha Dalvi

Q1) Write a program that prompts the user to input a year, checks
whether it's a leap year or not, and then prints the result.

#Write a program that prompts the user to input a year, checks whether it's a leap year or not, and
then prints the result.

year = int(input("Enter a year: "))

if (year % 4==0 and year % 100!=0):

print("It is a leap year.")

else:

print("It is not a leap year.")


Q2) Write a Python program that prompts the user to input a word.
The program should then determine and output the count of vowels
(a, e, i, o, u) in the provided word. Additionally, consider that the
word can be in either uppercase or lowercase.

word = input("Enter a word: ")

vowels = 'aeiouAEIOU'

count = 0

for char in word:

if char in vowels:

count = count+ 1

print("Number of vowels in the word:", count)


Q3) Write a Python program that allows the user to input a list of 6
names. After receiving the list, the program should print only the
names that start with the letter 'a', regardless of whether the letter is
uppercase or lowercase.

def main():

names = [input("Enter name {}: ".format(i)) for i in range(1, 7)]

print("Names starting with 'a' or 'A':")

for name in names:

if name.lower().startswith('a'):

print(name)

if __name__ == "__main__":

main()
Q4) Write a Python program that takes a list of 10 integers as input.
Your program should iterate through the list and print the following:
• For each even number encountered, print the number squared.
• For each odd number encountered, print the number cubed.

def main():

numbers = [int(input("Enter number {}: ".format(i + 1))) for i in range(10)]

for num in numbers:

if num % 2 == 0:

print(num ** 2)

else: # Odd number

print(num ** 3)

main()
Q5) Imagine you're ordering flowers from a local delivery service.
They offer a selection of beautiful flowers, including roses. Each
rose is priced at Rs. 10. Along with your choice of roses, you'll need
to provide the count of roses you wish to order and the delivery
distance. The delivery charges are as follows: Rs. 25 for distances
within 5 kilometers, Rs. 50 for distances between 5 and 10
kilometers, and Rs. 75 for distances greater than 10 kilometers.
Write a Python program that prompts the user to enter the count of
roses and the delivery distance, then calculates and displays the
total price to pay, including both the cost of roses and the delivery
charge.
def calculate_delivery_charge(distance):

if distance <= 5:

return 25

elif distance <= 10:

return 50

else:

return 75

def main():

rose_count = int(input("Enter the count of roses: "))

delivery_distance = float(input("Enter the delivery distance in kilometers: "))

rose_price = 10

total_rose_cost = rose_count * rose_price

delivery_charge = calculate_delivery_charge(delivery_distance)

total_price = total_rose_cost + delivery_charge

print("Total price to pay: Rs.", total_price)

main()

You might also like