Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Code it up:

1. Write a python code to print your name and address.

name = input("Enter your name: ")


print(name)

address = input("Enter your address:")


print (address)

mobile = input("Enter your mobile number:")


print(mobile)
2. Write the program in python to swap two numbers.

num1 = input('Enter First Number: ')


num2 = input('Enter Second Number: ')

print("Value of num1 before swapping: ", num1)


print("Value of num2 before swapping: ", num2)

# swapping two numbers using temporary variable


temp = num1
num1 = num2
num2 = temp

print("Value of num1 after swapping: ", num1)


print("Value of num2 after swapping: ", num2)

3. Write a program to add yours’ first and the last names and print the full
name.
firstname = input("Input your First Name : ")
lastname = input("Input your Last Name : ")
print (lastname + " " + firstname)

4. Write a program in python to find the area of a rectangle and area of a circle.

width = float(input('Please Enter the Width of a Rectangle: '))


height = float(input('Please Enter the Height of a Rectangle: '))
# calculate the area
Area = width * height
# calculate the Perimeter
Perimeter = 2 * (width + height)
print("\n Area of a Rectangle is: %.2f" %Area)
print(" Perimeter of Rectangle is: %.2f" %Perimeter)

5. Write a program in python to find the length of a string given.

str = "hello"
print(len(str))

6. Write a python code to add three numbers, taking the value from the user.
number1 = int(input("Please first number:"))
number2 = int(input("Please second number:"))
number3 = int(input("Please third number:"))
result = (number1 + number2 + number3) / 3
print("The sum of three numbers: " , result)

7. Write a program that asks the user to enter two integers. The program output
should be the quotient and remainder when the first number is divided by second
number. For example if the first number entered was 23 and the second number
entered was 4, then the program output should be quotient = 5 and remainder = 3.

a=int(input("Enter the first number: "))


b=int(input("Enter the second number: "))
quotient=a//b
remainder=a%b
print("Quotient is:",quotient)
print("Remainder is:",remainder)

8. Write a python program to find the area of a square, taking the value of the
side of a square from the user.
side = int(input("Enter the side of the : "))
Area = side*side
print("Area of the square="+ Area)

9. Write a program that asks the user to enter two integers. Have the program
output the two integers and the result when the first number entered is raised
to the power of the second number entered.

a=int(input("Enter the first number: "))


b=int(input("Enter the second number: "))
result=a**b
print("Square :",quotient)
10. Write a program in python to find the area of a triangle, taking the value of
base and height from the user.

base = float(input('Please Enter the Base of a Triangle: '))


height = float(input('Please Enter the Height of a Triangle: '))
# calculate the area
area = (base * height) / 2
print("The Area of a Triangle using", base, "and", height, " = ", area)

You might also like