0% found this document useful (0 votes)
3 views

Python Operations

Uploaded by

nickgemini2705
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Operations

Uploaded by

nickgemini2705
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter- Introduction to

Programming
Python Programs

1) Write a Python program which accepts the user's first and last name and print them.

firstname = input("What is your first name? ")

lastname = input("What is your last name? ")

print("Hello!", firstname ,lastname)

2) Write a Python program to add, subtract and multiply two numbers.

a = input("Input First Number:")

b = input("Input Second Number:")

sum = int(a)+int(b)

difference = int(a)-int(b)

print("The sum is" ,sum ,"and the difference is",difference)

3) Write a Python program to find simple interest.

Principal = input("Enter Principal: ")

Rate = input("Enter Rate: ")

Time = input("Enter Time: ")

simpleinterest = int(Principal)*int(Rate)*int(Time)

print("Simple Interest is", simpleinterest)

4) Write a Python program to calculate the area and perimeter of a rectangle.

l = input("Enter the length of the rectangle:")


b = input("Enter the breadth of the rectangle:")

area = int(l)*int(b)

perimeter= 2*(int(l)+int(b))

print("The area of the rectangle is", area, "and the perimeter is" ,perimeter)

5) Write a Python program to calculate the area and perimeter of a square.

s = input("Enter the side of the square:")

area = int(s)*int(s)

perimeter= int(s)*4

print("The area of the square is", area, "and the perimeter is" ,perimeter)

6) Write a Python program to calculate the area of a circle.

r = input ("Enter radius: ")

area = 22/7 * int(r) * int(r)

print ("The area of the circle is", area)

7) Write a Python program to calculate the square and cube of a number.

n = input ("Enter any number: ")

square = int(n) * int(n)

cube = int(n) * int(n) * int(n)

print ("The square of the number is", square,"and it's cube is", cube)

8) Write a Python program to three subject marks and calculate its total and average.

english = input ("Marks in English ")

math = input ("Marks in Math ")

science = input ("Marks in Science ")


total = int(english) + int(math) + int(science)

average = total / 3

print( "The total is", total,"and the average is",average)

9) Write a Python program to Celsius into Fahrenheit using the formula (Celsius *1.8)+32.

celsius = input("Enter a temperature in Celsius ")

fahrenheit = (int(celsius) * 1.8) + 32

print("The temperature in fahrenheit is", fahrenheit)

10) Write a Python program to swap values of two variables.

a= int(input("enter first number"))


b= int(input("enter second number"))
c=a
a=b
b=c
print(a,b)

11) Write a Python program to input a number and display its next two consecutive numbers.

n = input("Any Number:")

nextnumber = int(n)+1

nexPttonextnumber = int(n)+2

print("The number is", n, "and the next numbers are" ,nextnumber, "and",nexttonextnumber)

12) Write a Python program to convert Kilometres into metres.

km = input("Input kilometers:")

m = int(km)*1000
print("10 km in m is", m,'m')

13) Write a Python program to input temperature for all seven days and calculate the average

temperature of the week.

mon = input("Temperature on Monday:")

tue = input("Temperature on Tuesday:")

wed = input("Temperature on Wednesday:")

thu = input("Temperature on Thursday:")

fri = input("Temperature on Friday:")

sat = input("Temperature on Saturday:")

sun = input("Temperature on Sunday:")

average = (int(mon) + int(tue) + int(wed) + int(thu) + int(fri) + int(sat) + int(sun)) / 7

print ("The average is", average)

14) Write a program to join two strings (concatenate)

a = input("First string:")

b = input("Second string:")

concatenate = a + b

print(concatenate)

15) Write a program to display your school name 5 times.

schoolname = input ("Enter your school name:")

a = schoolname * 5

print (a)

You might also like