Task 2 .
write a program to read your name and print "hello<your_name>"
message.
user_name = input('Plz enter your name :')
print(f"Hello {user_name}")
Task 3. write a program to read two numbers and their sum, difference product and
division
num1 = int(input('plz enter your first number :'))
num2 = int(input ("plz enter your second number :"))
print(f"sum of your numbers : {num1 + num2}",'\n')
print(f"difference of your numbers : {num2 - num1}",'\n')
print(f"Product of your numbers : {num1 * num2}",'\n')
print(f"Division of your numbers : {num1 / num2}",'\n')
Task 4. write a program to read a string and character count of a given string
user_input_string = "upflairs pvt. ltd. jaipur rajasthan"
temp_dictionary = dict()
# reading each and every character from the given string
for char in user_input_string:
temp_dictionary[char] = user_input_string.count(char)
print("YOU GIVEN STRING IS :- ", user_input_string,'\n')
print("YOUR RESULT IS :",'\n')
print(temp_dictionary)
Task 5. Write a program to calculate the area of a given shape (rectangle , triangle ,
circle) reading shape and appropriate values from standard input.
import math
def area_of_rectangle(length,width):
"""Formula is : AREA = Length * Width
"""
area = length * width
print(f"Area of rectangle will be : {area}")
def area_of_tringle(base, height):
area = 0.5 * base * height
print(f"Area of tringle will be : {area}")
def calculate_circle_area(radius):
area = math.pi * radius ** 2
print(f"Area of circle will be : {area}")
message = """
Hello welcome to you in area calculator program.
choose specific option:
1. press R/r for rectangle
2. press T/t for tringle
3. press C/c for circle
"""
print(message)
user_operation = input('plz enter your option : ')
if user_operation.lower() == "r":
l = int(input('Plz enter the length : '))
w = int(input('Plz enter the width : '))
area_of_rectangle(l,w)
elif user_operation.lower() == "t":
base = int(input('Plz enter the base : '))
height = int(input('Plz enter the height : '))
area_of_tringle(base,height)
elif user_operation.lower() == "c":
radius = int(input("Plz enter the radius :"))
calculate_circle_area(radius)
else:
print("choose correct option!")
Task 6. write a program to print a name “n” times, where name and “n” are read from
standard input, using for loop and while loop.
name = input("Plz enter your name : ")
n = int(input("Plze enter the 'n' : "))
# using for loop
print("output using for loop")
for i in range(n):
print(name)
print()
print('output using while loop')
i = 0
while i < n:
print(name)
i +=1
Task 7. write a program to handle divided by zero exception
num1 = int(input('Plz enter the first number : '))
num2 = int(input('Plz enter the second number : '))
try:
result = num1/num2
print(result)
except ZeroDivisionError as z:
print()
print("Plz dont insert zero !")
num1 = int(input('Plz enter the first number : '))
num2 = int(input('Plz enter the second number : '))
result = num1/num2
print(result)
Task 8. write a program to print current time for 10 times with
an interval of 10 seconds:
from datetime import datetime
import time
for i in range(10):
print(datetime.now())
time.sleep(10)
Task 9. write a program to read a file line by line and print the
word count of each line
with open('text_file.txt','r') as file:
lines_data = file.readlines()
word_count_temp = {}
for line in lines_data:
words_list = line.split(" ")
for word in words_list:
word_count_temp[word] = line.count(word)
print("<<<<<<< Line >>>>>>>")
print(word_count_temp)