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

Python Programming Code For Practice

The document provides 9 code examples demonstrating various Python programming concepts. The codes cover arithmetic operations, drawing shapes with Turtle graphics, temperature conversions, evaluating conditional expressions, and more. Students are instructed to practice the given codes for their final term.

Uploaded by

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

Python Programming Code For Practice

The document provides 9 code examples demonstrating various Python programming concepts. The codes cover arithmetic operations, drawing shapes with Turtle graphics, temperature conversions, evaluating conditional expressions, and more. Students are instructed to practice the given codes for their final term.

Uploaded by

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

PYTHON PRACTICAL CODES FOR FINAL TERM

PRCATICE THE GIVEN CODES

a = 7
b = 2

# addition
print ('Sum: ', a + b)

# subtraction
print ('Subtraction: ', a - b)

# multiplication
print ('Multiplication: ', a * b)

# division
print ('Division: ', a / b)

# floor division
print ('Floor Division: ', a // b)

# modulo
print ('Modulo: ', a % b)

# a to the power b
print ('Power: ', a ** b)

CODE 1:

PYTHON CODE TO ADD, SUBTRACT, MULTIPLY, DIVIDE, MODULO, POWER.


PYTHON PRACTICAL CODES FOR FINAL TERM

PRCATICE THE GIVEN CODES

CODE 2: DRAW TRAINGLE


import turtle

t = turtle.Turtle()

def draw_triangle(side_length):
for i in range(0,3):
t.forward(side_length)
t.right(120)

draw_triangle(100)
PYTHON PRACTICAL CODES FOR FINAL TERM

PRCATICE THE GIVEN CODES

CODE 3: DRAW SQUARE

# draw Square in Python Turtle


import turtle
  
t = turtle.Turtle()
 
s = int(input("Enter the length of the side of square: "))
 
for _ in range(4):
  t.forward(s) # Forward turtle by s units
  t.left(90) # Turn turtle by 90 degree
PYTHON PRACTICAL CODES FOR FINAL TERM

PRCATICE THE GIVEN CODES

CODE 4: CELSIUS TO FAHRENHEIT CONVERSION:

celsius = 54
fahrenheit = (celsius * 1.8) + 32
print(str(celsius )+ " degree Celsius is equal to " + str(fahrenheit )+ " degree Fahrenheit.")

CODE 5: FAHRENHEIT TO CELSIUS CONVERSION

fahrenheit = float(input("Please give the fahrenheit Temperature : "))

#converting Celsius into Fahrenheit

celsius = ((fahrenheit-32)*5)/9

print("Celcius= ",celsius)
PYTHON PRACTICAL CODES FOR FINAL TERM

PRCATICE THE GIVEN CODES

CODE 6: Draw Triangle

# Python program to demonstrate


# tangent circle drawing
  
  
import turtle
    
t = turtle.Turtle()
  
# radius for smallest circle
r = 10
  
# number of circles
n = 10
  
# loop for printing tangent circles
for i in range(1, n + 1, 1):
    t.circle(r * i)
PYTHON PRACTICAL CODES FOR FINAL TERM

PRCATICE THE GIVEN CODES

CODE 7:

SHOW VALUE OF X,Y AND Z

x = 35e3
y = 12E4
z = -87.7e100

print(type(x))
print(type(y))
print(type(z))

CODE 8: WHEN IS GREATER THAN B AND A AND B ARE EQUAL.


a = 33
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")

CODE 9:

Example
Test if a is greater than b, AND if c is greater than a:

a = 200
b = 33
c = 500
if a > b and c > a:
  print("Both conditions are True")

You might also like