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

Cheat Code

The document provides Python code snippets for various tasks including calculating the area of a rectangle and a circle, converting distances between kilometers and meters, converting temperatures between Fahrenheit and Celsius, and basic arithmetic operations. It also includes examples of how to use the print function, perform variable swapping with and without a third variable, and demonstrates combined arithmetic operations. Each code snippet is accompanied by user input prompts and output statements.

Uploaded by

vanshupadhyay147
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

Cheat Code

The document provides Python code snippets for various tasks including calculating the area of a rectangle and a circle, converting distances between kilometers and meters, converting temperatures between Fahrenheit and Celsius, and basic arithmetic operations. It also includes examples of how to use the print function, perform variable swapping with and without a third variable, and demonstrates combined arithmetic operations. Each code snippet is accompanied by user input prompts and output statements.

Uploaded by

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

All codes for python

1.for rectangle
# Define the length and width of the
rectangle
length = float(input("Enter the length
of the rectangle: "))
width = float(input("Enter the width of
the rectangle: "))

# Calculate the area


area = length * width

# Print the result


print("The area of the rectangle is:",
area)

2.for circle
import math

# Ask the user for the radius of the


circle
radius = float(input("Enter the radius
of the circle: "))

# Calculate the area using the formula


area = math.pi * radius ** 2

# Print the result


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

3.to convert kilometers to meters


# Ask the user for the number of
kilometers
kilometers = float(input("Enter the
distance in kilometers: "))

# Convert kilometers to meters


meters = kilometers * 1000

# Print the result


print(f"{kilometers} kilometers is equal
to {meters} meters.")
4.to convert meters to kilometers
# Ask the user for the number of
meters
meters = float(input("Enter the
distance in meters: "))

# Convert meters to kilometers


kilometers = meters / 1000

# Print the result


print(f"{meters} meters is equal to
{kilometers} kilometers.")

5.to convert fahraneit to celsius


# Ask the user for the temperature in
Fahrenheit
fahrenheit = float(input("Enter the
temperature in Fahrenheit: "))

# Convert Fahrenheit to Celsius


celsius = (fahrenheit - 32) / 1.8
# Print the result
print(f"{fahrenheit} Fahrenheit is equal
to {celsius} Celsius.")

6.to convert Celsius to Fahrenheit


# Ask the user for the temperature in
Celsius
celsius = float(input("Enter the
temperature in Celsius: "))

# Convert Celsius to Fahrenheit


fahrenheit = (celsius * 1.8) + 32

# Print the result


print(f"{celsius} Celsius is equal to
{fahrenheit} Fahrenheit.")

7.how to use print function


print (“expression”)
Ex- print (“7i world school”)

8.how to add ,subtract ,multiply ,divide


x = 10
y=5

# Addition
result = x + y
print("Addition:", result)

x = 10
y=5

# Subtraction
result = x - y
print("Subtraction:", result) # Output:
5

x = 10
y=5

# Multiplication
result = x * y
print("Multiplication:", result) #
Output: 50
x = 10
y=5

# Division
result = x / y
print("Division:", result)

x = 10
y=5
z=2

# Combined operations
result = (x + y) * z / (x - z)
print("Combined Result:", result)

9.how to use arthimetic operation


a = input (“Enter a number :”)
b= input (“Enter another number:”)
print (“The answer is:” , int(a) + int(b))

note- just change the sign to do


different operation
10.to swap two variables using third
variable
a= int (input(“Enter value for a =”))
b= int (input(“Enter value for b =”))
t= a
a=b
b=t
print (“After swapped A =” , a)
print (“B =” , b)

11. .to swap two variables without


using third variable
a = a+b
b = a-b
a = a-b
print (“After swapped A =” , a)
print (“ B =” , b)

You might also like