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

PYTHON PRACT CODES

The document contains various Python code snippets demonstrating basic programming concepts. It includes personalized greetings, area calculations for geometric figures, gross salary computation for employees, arithmetic operations, triangle pattern generation, number type identification, factorial generation, and prime number analysis. Each code snippet is designed to perform a specific task based on user input.

Uploaded by

Sneha Garde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PYTHON PRACT CODES

The document contains various Python code snippets demonstrating basic programming concepts. It includes personalized greetings, area calculations for geometric figures, gross salary computation for employees, arithmetic operations, triangle pattern generation, number type identification, factorial generation, and prime number analysis. Each code snippet is designed to perform a specific task based on user input.

Uploaded by

Sneha Garde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PYTHON CODES

1] Personalized gree ng

name = input("Enter your name: ")


print("Welcome!", name)

2] Calcula ng area of geometric figures


n = input("Choose a shape (circle, rectangle, triangle): ")

if n == "circle":
r = float(input("Enter radius: "))
print("Area:", 3.1416 * r ** 2)

elif n == "rectangle":
l = float(input("Enter length: "))
w = float(input("Enter width: "))
print("Area:", l * w)

elif n == "triangle":
b = float(input("Enter base: "))
h = float(input("Enter height: "))
print("Area:", 0.5 * b * h)

else:
print("Invalid input!")
3] Gross salary of employee
basic=int(input(“Enter your salary : ”, basic)
HRA=0.1*basic
DA=0.7*basic
TA=0.3*basic
gross = (basic+HRA+DA+TA)
print(“Salary of employee is : ” ,gross)

4] Basic aritheme c opera ons


a=int(input("Enter the value of a :"))
b=int(input("Enter the value of b:"))
print("ADDITION:", a+b)
print("SUBTRACTION:", a-b)
print("MULTIPLICATION:", a*b)
print("DIVISION:", a/b)
print("MODULUS:", a%b)
Note: if you want the vale of (a & b )as float instead of int() use float()

5] Triangle pa ern generator


def print_triangle(rows):
for i in range(1, rows + 1):
print(' ' * (rows - i), end='')
print('* ' * i)
num_rows = int(input("Enter the number of rows for the triangle: "))
print_triangle(num_rows)
6] Number type iden fier
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even Number")
else:
print("Odd Number")

7] Factorial generator
import math

num = int(input("Enter a number: "))


print("Factorial:", math.factorial(num))

8] Prime number analyzer


num = int(input("Enter a number: "))

if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not Prime")
else:
print("Prime")

You might also like