1.
Convert the given temperature from Fahrenheit to Celsius and vice versa
PROGRAM:
f=float(input("enter the fahrenheit"))
c=(f-32)*5/9
print("the celsius value is",c)
c=float(input("enter the celsius"))
f=(c*9/5)+32
print("the fahrenheit value is",f)
OUTPUT:
enter the fahrenheit50
the celsius value is 10.0
enter the celsius60
the fahrenheit value is 140.0
2. Construct the following pattern, using a nested loop
PROGRAM:
row=4
for i in range(1,row+1):
print(" "*(row-i)+"*"*i)
for i in range(row-1,0,-1):
print(" "*(row-i)+"*"*i)
OUTPUT:
*
* *
* * *
* * * *
* * *
**
*
3. Student Mark Statement
PROGRAM:
subject1=float(input("enter marks for subject1:"))
subject2=float(input("enter maks for subject2:"))
subject3=float(input("enter marks for subject3:"))
subject4=float(input("entermarks for subject4:"))
subject5=float(input("enter marks for subject5:"))
total_marks=subject1+subject2+subject3+subject4+subject5
total_subjects=5
percentage=(total_marks/(total_subjects*100))*100
if percentage>=80:
grade='A'
elif percentage>=70 and 80:
grade='B'
elif percentage>=60 and 70:
grade='C'
elif percentage>=40 and 50:
grade='D'
else:
grade='E'
print("total marks:",total_marks)
print("percentage:",percentage,"%")
print("grade:",grade)
OUTPUT:
enter marks for subject1:65
enter maks for subject2:76
enter marks for subject3:45
entermarks for subject4:78
enter marks for subject5:63
total marks: 327.0
percentage: 65.4 %
grade: C
4. Find the area of rectangle, square, circle and triangle
PROGRAM:
l=int(input("enter the valueof length"))
b=int(input("enter the value of breath"))
area=l*b
print("the area of rectangle is",area)
a=int(input("enter the side value "))
area=a*a
print("the area of square is",area)
r=int(input("enter the radius"))
a=3.14*r*r
print("the area of circle is",area)
b=int(input("enter the base value"))
h=int(input("enter thr height value"))
area=1/2*b*h
print("the area of triangle is",area)
OUTPUT:
enter the valueof length70
enter the value of breath65
the area of rectangle is 4550
enter the side value 20
the area of square is 400
enter the radius49
the area of circle is 400
enter the base value24
enter thr height value45
the area of triangle is 540.0
5. Print prime numbers less than20.
PROGRAM:
print("The Prime numbers less than 20 are..")
for i in range(2,21):
for j in range(2,i):
if i%j ==0:
break
else:
print(i,end=",")
OUTPUT:
The Prime numbers less than 20 are..
2,3,5,7,11,13,17,19,
6. Find factorial of the given number using recursive function.
PROGRAM:
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))
num =int(input("enter n value"))
print("The factorial of", num, "is", factorial(num))
OUTPUT:
enter n value9
The factorial of 9 is 362880
8. Reverse a string word by word.
PROGRAM:
class streverse:
def reverse_words(self, s):
return ' '.join(reversed([Link]()))
st=input("enter any string")
print(streverse().reverse_words(st))
OUTPUT:
enter any string
welcome to python programming
programming python to welcome
9. Read a file content and copy only the contents and odd lines into a new file.
PROGRAM:
def copy_odd_lines(input_file, output_file):
with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
for line_number, line in enumerate(infile, 1):
if line_number % 2 != 0:
[Link](line)
input_file_name = '[Link]'
output_file_name = '[Link]'
copy_odd_lines(input_file_name, output_file_name)
OUTPUT:
[Link]:
Top 11 Features of Python You Must Know
Easy To Learn and Readable Language.
Interpreted Language.
Dynamically Typed Language.
Open Source And Free.
Large Standard Library.
High-Level Language.
Object Oriented Programming Language.
Large Community Support.
[Link]:
Top 11 Features of Python You Must Know
Interpreted Language.
Open Source And Free.
High-Level Language.
Large Community Support.
10. Create a Turtle graphics window with specific size.
PROGRAM:
import turtle
drawing_area=[Link]()
drawing_area.setup(width=550,height=330)
drawing_area.bgcolor("red")
drawing_area.title("hai my turtle")
OUTPUT:
7. To count the number of even and odd numbers from array of ‘N’ numbers.
PROGRAM:
list1=[10,21,4,45,66,93,1]
even_count=0
odd_count=0
for num in list1:
if num%2==0:
even_count+=1
else:
odd_count+=1
print("even number in the list",even_count)
print("odd number in the list",odd_count)
OUTPUT:
even number in the list 3
odd number in the list 4