0% found this document useful (0 votes)
24 views5 pages

Capsule 1

The document contains five Python programming tasks that involve user input and basic calculations. Tasks include greeting a user, swapping values, calculating the area of a circle, determining age from birth year, and generating a personalized birthday message. Additionally, it includes a task for calculating simple interest based on user-provided principal, rate, and time.

Uploaded by

Rochit Limje
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)
24 views5 pages

Capsule 1

The document contains five Python programming tasks that involve user input and basic calculations. Tasks include greeting a user, swapping values, calculating the area of a circle, determining age from birth year, and generating a personalized birthday message. Additionally, it includes a task for calculating simple interest based on user-provided principal, rate, and time.

Uploaded by

Rochit Limje
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
You are on page 1/ 5

Q1) Write a Python program that takes user input for their name and greets the user.

Then, prompt
the user to enter two values. After receiving the values, swap them and print both the ordiginal
values and the swapped values.

name = input("Enter your name: ")

print(f"Hello, {name}!")

val1 = float(input("Enter the first value: "))

val2 = float(input("Enter the second value: "))

print("Original values:", val1, val2)

# Swap values

temp = val1

val1 = val2

val2 = temp

print("Swapped values:", val1, val2)


Q2) Write a Python program that asks the user to input the radius of a circle. Calculate the area of
the circle using the formula area = π * radius^2, where π (pi) is a constant approximately equal to
3.14. Print out the calculated area. Ensure that the user input for the radius is converted to a float
data type before performing calculations.

pi = 3.14 # Constant value for pi

radius = float(input("Enter the radius of the circle: "))

area = pi * radius**2

print("Area of the circle:", area)


Q3) Write a Python program where the user is prompted to input their birth year. The program
should then calculate and display the user's current age.

birth_year = int(input("Enter your birth year: "))

current_year = 2024 # Assuming the current year is 2024

age = current_year - birth_year

print("Your current age:", age)


Q4) Imagine you're a bakery owner and you want to personalize messages for your customers.

Write a Python program where customers are prompted to input their name and favorite cake flavor.
The program should then print a customized message saying: "Hello, [name]! We're delighted to
serve you your favorite [favorite_cake] cake on your birthday. Happy Birthday."

name = input("Enter your name: ")

favorite_cake = input("What's your favorite cake flavor? ")

message = f"Hello, {name}! We're delighted to serve you your favorite {favorite_cake} cake on your
birthday. Happy Birthday!"

print(message)
Q5) Write a Python program to calculate the simple interest with user input for principal amount,
rate, and time.

principal = float(input("Enter the principal amount: "))

rate = float(input("Enter the interest rate (in percentage): "))

time = float(input("Enter the time period (in years): "))

# Convert rate to decimal

rate = rate / 100

simple_interest = (principal * rate * time)

print("Simple Interest:", simple_interest)

You might also like