DAY1 Assignments Solutions
DAY1 Assignments Solutions
example
name=input("enter your name: ")
Note 2: For assignments you might need to use some of the string methods that were
not discussed in class. You can refer to below link for reference:
https://www.w3schools.com/python/python_ref_string.asp
1- write a program which takes 2 inputs from the user : weight(kg) and
height(meter) and prints the BMI in the output.
solution:
weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in meters: "))
2- write a program which takes the name of the user as input and replace all the
occurence of character 'a' in the name to 'b' and print it.
solution:
name = input("Enter your name: ")
3- write a program which takes 2 inputs from user as principle amount (int) and
rate of annual interest (float) and print the expected total amount after 2
years.
example : principle : 100 , interest percent 10 then amount after 2 years will
be : 100*1.1*1.1 = 121
solution:
principal = int(input("Enter the principal amount: "))
interest_rate = float(input("Enter the annual interest rate: "))
4- write a program which takes city name from user input. irrespective of in which
case user enters the city name, print the city name in camel case meaning first
letter should be capital and rest in small.
solution 1:
city_name = input("Enter the city name: ")
# Convert the city name to lowercase
city_name = city_name.lower()
solution 2:
city_name = input("Enter the city name: ")
5- write a program which takes the name of the user as input and print the index of
character 'a' in the string. if 'a' is not there then return -1.
solution:
index = name.find('a')
solution : print(len(my_word))
7- take 3 inputs from user : first name , last name and age . Display the
information in below format
exmaple
first name : MOhit
last name : sharma
age 32
note that first letter of first name and last name both should be in capital
letters and rest in small.
solution:
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
age = input("Enter your age: ")
# Format the first and last name with capitalizing the first letter
formatted_first_name = first_name.capitalize()
formatted_last_name = last_name.capitalize()
#please note above this is a new way to print along with variables using comma.
8-take 3 inputs from user : first name , last name and company name. create the
email alias for the user and display it. Email alias is first 2 letters of first
name , last 3 letters of last name and @company.com
example
first name : MOhit
last name : sharma
company : infosys
Display : [email protected]
solution: