Q1) Write a python program to take your name and surname
individually and print them together.
Code:
name=input("Enter your name: ").strip()
sur_name=input("Enter your surname: ").strip()
print(name+' '+sur_name)
Output:
Q2)Write a python program to find out the square root of any
number.(without using inbuilt math module)
Code:
num=int(input("Enter number here: "))
sqr=int(num ** 0.5)
print("Your answer:",sqr)
Output:
Q3) Write a python program to take any word from the user as
input and show how many characters it contains.
Code:
enter_string=input().strip()
count=0
for i in range (0,len(enter_string)):
if(enter_string[i]!=' '):
count+=1
print("Number of charactars: ",count)
Output:
Q4) Write a python program to find out the ASCII value of any
given character.
Code:
mychar=input("Enter any character:").strip()
ascii_myhar=ord(mychar)
print(ascii_myhar)
Output:
Q5) Write a python program to open Google homepage.(Use
'import web browser')
Code:
import webbrowser
webbrowser.open('https://www.google.com')
Output:
Opens google homepage
Q6) Write a python program to implement Fibonacci series
within a given range of numbers
Code:
no_fibs=int(input("Enter the range for the fibonacii:"))
n1,n2=0,1
if no_fibs<=0:
print("Not allowed!")
elif no_fibs==1:
print(n1)
else:
print("Fibonacii:")
for i in range(0,no_fibs):
print(n1)
nth=n1+n2
n1=n2
n2=nth
Output:
Q7)Write a python program to show any given year is leap year
or not.
Code:
enter_year=int(input("Enter any year:"))
if(((enter_year%4==0) and (enter_year%100!=0)) or (enter_year
%400==0)):
print("The year ",enter_year," is a leapyear")
else:
print("The year ",enter_year," is not a leapyear")
Output:
Q8)Write a python program to find out the HCF and LCM of two
numbers.
Code:
a=int(input())
b=int(input())
if(b<a):
a,b=b,a
if a==0:
print("hcf",b)
print("LCM",a)
else:
l=a
r=b
while(a!=0):
c=a
a=b%a
b=c
print("HCF of(",l,r,") is ", b)
lcm=(l*r)//b
print("LCM of(",l,r,") is ",lcm)
Output:
Q9) Write a python program to check a given number is
Armstrong number or not.
Code:
num=int(input("Enter the number"))
temp=num
count=0
while(temp != 0):
temp= temp // 10
count+=1
temp=num
sum=0
while(temp != 0):
rem= temp % 10
temp= temp // 10
sum=sum+(rem**count)
if(sum==num):
print("armstrong")
else:
print("not Armstrong")
Output:
Q10) Write a python program to calculate area and
circumference of a circle by taking the radius as input from user.
Code:
import math as m
def circle(rad):
ar = (m.pi * (rad ** 2))
cir = (2 * m.pi * rad)
print("area of the circle is:","%.2f"%ar," and cicumference of
circle is:","%.2f"%cir)
rad=int(input("Enter radius:"))
circle(rad)
Output: